Use C++17 [[nodiscard]] and [[fallthrough]] attributes
Bug: dawn:824 Change-Id: Ied4f2eb736e0c3488a79e4872e7ffa3eb2fdaac5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/75063 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Loko Kung <lokokung@google.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
3f011e6807
commit
2994d2e7b9
|
@ -530,7 +530,7 @@
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DAWN_NO_DISCARD WireResult SerializeChainedStruct({{ChainedStructPtr}} chainedStruct,
|
[[nodiscard]] WireResult SerializeChainedStruct({{ChainedStructPtr}} chainedStruct,
|
||||||
SerializeBuffer* buffer,
|
SerializeBuffer* buffer,
|
||||||
const ObjectIdProvider& provider) {
|
const ObjectIdProvider& provider) {
|
||||||
ASSERT(chainedStruct != nullptr);
|
ASSERT(chainedStruct != nullptr);
|
||||||
|
@ -702,7 +702,7 @@ namespace dawn_wire {
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t GetChainedStructExtraRequiredSize(const WGPUChainedStruct* chainedStruct);
|
size_t GetChainedStructExtraRequiredSize(const WGPUChainedStruct* chainedStruct);
|
||||||
DAWN_NO_DISCARD WireResult SerializeChainedStruct(const WGPUChainedStruct* chainedStruct,
|
[[nodiscard]] WireResult SerializeChainedStruct(const WGPUChainedStruct* chainedStruct,
|
||||||
SerializeBuffer* buffer,
|
SerializeBuffer* buffer,
|
||||||
const ObjectIdProvider& provider);
|
const ObjectIdProvider& provider);
|
||||||
WireResult DeserializeChainedStruct(const WGPUChainedStruct** outChainNext,
|
WireResult DeserializeChainedStruct(const WGPUChainedStruct** outChainNext,
|
||||||
|
@ -711,7 +711,7 @@ namespace dawn_wire {
|
||||||
const ObjectIdResolver& resolver);
|
const ObjectIdResolver& resolver);
|
||||||
|
|
||||||
size_t GetChainedStructExtraRequiredSize(WGPUChainedStructOut* chainedStruct);
|
size_t GetChainedStructExtraRequiredSize(WGPUChainedStructOut* chainedStruct);
|
||||||
DAWN_NO_DISCARD WireResult SerializeChainedStruct(WGPUChainedStructOut* chainedStruct,
|
[[nodiscard]] WireResult SerializeChainedStruct(WGPUChainedStructOut* chainedStruct,
|
||||||
SerializeBuffer* buffer,
|
SerializeBuffer* buffer,
|
||||||
const ObjectIdProvider& provider);
|
const ObjectIdProvider& provider);
|
||||||
WireResult DeserializeChainedStruct(WGPUChainedStructOut** outChainNext,
|
WireResult DeserializeChainedStruct(WGPUChainedStructOut** outChainNext,
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
// - DAWN_COMPILER_[CLANG|GCC|MSVC]: Compiler detection
|
// - DAWN_COMPILER_[CLANG|GCC|MSVC]: Compiler detection
|
||||||
// - DAWN_BREAKPOINT(): Raises an exception and breaks in the debugger
|
// - DAWN_BREAKPOINT(): Raises an exception and breaks in the debugger
|
||||||
// - DAWN_BUILTIN_UNREACHABLE(): Hints the compiler that a code path is unreachable
|
// - DAWN_BUILTIN_UNREACHABLE(): Hints the compiler that a code path is unreachable
|
||||||
// - DAWN_NO_DISCARD: An attribute that is C++17 [[nodiscard]] where available
|
|
||||||
// - DAWN_(UN)?LIKELY(EXPR): Where available, hints the compiler that the expression will be true
|
// - DAWN_(UN)?LIKELY(EXPR): Where available, hints the compiler that the expression will be true
|
||||||
// (resp. false) to help it generate code that leads to better branch prediction.
|
// (resp. false) to help it generate code that leads to better branch prediction.
|
||||||
// - DAWN_UNUSED(EXPR): Prevents unused variable/expression warnings on EXPR.
|
// - DAWN_UNUSED(EXPR): Prevents unused variable/expression warnings on EXPR.
|
||||||
|
@ -51,15 +50,6 @@
|
||||||
# define __has_cpp_attribute(name) 0
|
# define __has_cpp_attribute(name) 0
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
// Use warn_unused_result on clang otherwise we can a c++1z extension warning in C++14 mode
|
|
||||||
// Also avoid warn_unused_result with GCC because it is only a function attribute and not a type
|
|
||||||
// attribute.
|
|
||||||
# if __has_cpp_attribute(warn_unused_result) && defined(__clang__)
|
|
||||||
# define DAWN_NO_DISCARD __attribute__((warn_unused_result))
|
|
||||||
# elif DAWN_CPP_VERSION >= 17 && __has_cpp_attribute(nodiscard)
|
|
||||||
# define DAWN_NO_DISCARD [[nodiscard]]
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# define DAWN_DECLARE_UNUSED __attribute__((unused))
|
# define DAWN_DECLARE_UNUSED __attribute__((unused))
|
||||||
# if defined(NDEBUG)
|
# if defined(NDEBUG)
|
||||||
# define DAWN_FORCE_INLINE inline __attribute__((always_inline))
|
# define DAWN_FORCE_INLINE inline __attribute__((always_inline))
|
||||||
|
@ -75,11 +65,6 @@ extern void __cdecl __debugbreak(void);
|
||||||
|
|
||||||
# define DAWN_BUILTIN_UNREACHABLE() __assume(false)
|
# define DAWN_BUILTIN_UNREACHABLE() __assume(false)
|
||||||
|
|
||||||
// Visual Studio 2017 15.3 adds support for [[nodiscard]]
|
|
||||||
# if _MSC_VER >= 1911 && DAWN_CPP_VERSION >= 17
|
|
||||||
# define DAWN_NO_DISCARD [[nodiscard]]
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# define DAWN_DECLARE_UNUSED
|
# define DAWN_DECLARE_UNUSED
|
||||||
# if defined(NDEBUG)
|
# if defined(NDEBUG)
|
||||||
# define DAWN_FORCE_INLINE __forceinline
|
# define DAWN_FORCE_INLINE __forceinline
|
||||||
|
@ -102,9 +87,6 @@ extern void __cdecl __debugbreak(void);
|
||||||
#if !defined(DAWN_UNLIKELY)
|
#if !defined(DAWN_UNLIKELY)
|
||||||
# define DAWN_UNLIKELY(X) X
|
# define DAWN_UNLIKELY(X) X
|
||||||
#endif
|
#endif
|
||||||
#if !defined(DAWN_NO_DISCARD)
|
|
||||||
# define DAWN_NO_DISCARD
|
|
||||||
#endif
|
|
||||||
#if !defined(DAWN_FORCE_INLINE)
|
#if !defined(DAWN_FORCE_INLINE)
|
||||||
# define DAWN_FORCE_INLINE inline
|
# define DAWN_FORCE_INLINE inline
|
||||||
#endif
|
#endif
|
||||||
|
@ -112,10 +94,4 @@ extern void __cdecl __debugbreak(void);
|
||||||
# define DAWN_NOINLINE
|
# define DAWN_NOINLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
# define DAWN_FALLTHROUGH [[clang::fallthrough]]
|
|
||||||
#else
|
|
||||||
# define DAWN_FALLTHROUGH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // COMMON_COMPILER_H_
|
#endif // COMMON_COMPILER_H_
|
||||||
|
|
|
@ -134,7 +134,7 @@ class RefBase {
|
||||||
return mValue;
|
return mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
T Detach() DAWN_NO_DISCARD {
|
[[nodiscard]] T Detach() {
|
||||||
T value{std::move(mValue)};
|
T value{std::move(mValue)};
|
||||||
mValue = Traits::kNullValue;
|
mValue = Traits::kNullValue;
|
||||||
return value;
|
return value;
|
||||||
|
@ -145,7 +145,7 @@ class RefBase {
|
||||||
mValue = value;
|
mValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* InitializeInto() DAWN_NO_DISCARD {
|
[[nodiscard]] T* InitializeInto() {
|
||||||
ASSERT(mValue == Traits::kNullValue);
|
ASSERT(mValue == Traits::kNullValue);
|
||||||
return &mValue;
|
return &mValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Result;
|
||||||
// Specialization of Result for returning errors only via pointers. It is basically a pointer
|
// Specialization of Result for returning errors only via pointers. It is basically a pointer
|
||||||
// where nullptr is both Success and Empty.
|
// where nullptr is both Success and Empty.
|
||||||
template <typename E>
|
template <typename E>
|
||||||
class DAWN_NO_DISCARD Result<void, E> {
|
class [[nodiscard]] Result<void, E> {
|
||||||
public:
|
public:
|
||||||
Result();
|
Result();
|
||||||
Result(std::unique_ptr<E> error);
|
Result(std::unique_ptr<E> error);
|
||||||
|
@ -109,7 +109,7 @@ namespace detail {
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
class DAWN_NO_DISCARD Result<T*, E> {
|
class [[nodiscard]] Result<T*, E> {
|
||||||
public:
|
public:
|
||||||
static_assert(alignof_if_defined_else_default<T, 4> >= 4,
|
static_assert(alignof_if_defined_else_default<T, 4> >= 4,
|
||||||
"Result<T*, E*> reserves two bits for tagging pointers");
|
"Result<T*, E*> reserves two bits for tagging pointers");
|
||||||
|
@ -141,7 +141,7 @@ class DAWN_NO_DISCARD Result<T*, E> {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
class DAWN_NO_DISCARD Result<const T*, E> {
|
class [[nodiscard]] Result<const T*, E> {
|
||||||
public:
|
public:
|
||||||
static_assert(alignof_if_defined_else_default<T, 4> >= 4,
|
static_assert(alignof_if_defined_else_default<T, 4> >= 4,
|
||||||
"Result<T*, E*> reserves two bits for tagging pointers");
|
"Result<T*, E*> reserves two bits for tagging pointers");
|
||||||
|
@ -170,7 +170,7 @@ template <typename T>
|
||||||
class Ref;
|
class Ref;
|
||||||
|
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
class DAWN_NO_DISCARD Result<Ref<T>, E> {
|
class [[nodiscard]] Result<Ref<T>, E> {
|
||||||
public:
|
public:
|
||||||
static_assert(alignof_if_defined_else_default<T, 4> >= 4,
|
static_assert(alignof_if_defined_else_default<T, 4> >= 4,
|
||||||
"Result<Ref<T>, E> reserves two bits for tagging pointers");
|
"Result<Ref<T>, E> reserves two bits for tagging pointers");
|
||||||
|
@ -205,7 +205,7 @@ class DAWN_NO_DISCARD Result<Ref<T>, E> {
|
||||||
// a tagged union instead if it turns out to be a hotspot. T and E must be movable and default
|
// a tagged union instead if it turns out to be a hotspot. T and E must be movable and default
|
||||||
// constructible.
|
// constructible.
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
class DAWN_NO_DISCARD Result {
|
class [[nodiscard]] Result {
|
||||||
public:
|
public:
|
||||||
Result(T&& success);
|
Result(T&& success);
|
||||||
Result(std::unique_ptr<E> error);
|
Result(std::unique_ptr<E> error);
|
||||||
|
|
|
@ -217,7 +217,7 @@ namespace dawn_native {
|
||||||
"Filtering sampler %s is incompatible with non-filtering sampler "
|
"Filtering sampler %s is incompatible with non-filtering sampler "
|
||||||
"binding.",
|
"binding.",
|
||||||
entry.sampler);
|
entry.sampler);
|
||||||
DAWN_FALLTHROUGH;
|
[[fallthrough]];
|
||||||
case wgpu::SamplerBindingType::Filtering:
|
case wgpu::SamplerBindingType::Filtering:
|
||||||
DAWN_INVALID_IF(
|
DAWN_INVALID_IF(
|
||||||
entry.sampler->IsComparison(),
|
entry.sampler->IsComparison(),
|
||||||
|
|
|
@ -33,13 +33,11 @@ namespace dawn {
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
enum class InternalErrorType : uint32_t;
|
enum class InternalErrorType : uint32_t;
|
||||||
|
|
||||||
class DAWN_NO_DISCARD ErrorData {
|
class [[nodiscard]] ErrorData {
|
||||||
public:
|
public:
|
||||||
static DAWN_NO_DISCARD std::unique_ptr<ErrorData> Create(InternalErrorType type,
|
[[nodiscard]] static std::unique_ptr<ErrorData> Create(
|
||||||
std::string message,
|
InternalErrorType type, std::string message, const char* file, const char* function,
|
||||||
const char* file,
|
int line);
|
||||||
const char* function,
|
|
||||||
int line);
|
|
||||||
ErrorData(InternalErrorType type, std::string message);
|
ErrorData(InternalErrorType type, std::string message);
|
||||||
|
|
||||||
struct BacktraceRecord {
|
struct BacktraceRecord {
|
||||||
|
|
|
@ -1275,7 +1275,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
switch (descriptor->dimension) {
|
switch (descriptor->dimension) {
|
||||||
case wgpu::TextureViewDimension::e2DArray:
|
case wgpu::TextureViewDimension::e2DArray:
|
||||||
ASSERT(texture->GetArrayLayers() == 1);
|
ASSERT(texture->GetArrayLayers() == 1);
|
||||||
DAWN_FALLTHROUGH;
|
[[fallthrough]];
|
||||||
case wgpu::TextureViewDimension::e2D:
|
case wgpu::TextureViewDimension::e2D:
|
||||||
ASSERT(texture->GetDimension() == wgpu::TextureDimension::e2D);
|
ASSERT(texture->GetDimension() == wgpu::TextureDimension::e2D);
|
||||||
mSrvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMS;
|
mSrvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMS;
|
||||||
|
|
|
@ -756,7 +756,7 @@ namespace dawn_native { namespace opengl {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Implementation for 2D array is the same as 3D.
|
// Implementation for 2D array is the same as 3D.
|
||||||
DAWN_FALLTHROUGH;
|
[[fallthrough]];
|
||||||
}
|
}
|
||||||
|
|
||||||
case wgpu::TextureDimension::e3D: {
|
case wgpu::TextureDimension::e3D: {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
namespace dawn_wire {
|
namespace dawn_wire {
|
||||||
|
|
||||||
enum class DAWN_NO_DISCARD WireResult {
|
enum class [[nodiscard]] WireResult{
|
||||||
Success,
|
Success,
|
||||||
FatalError,
|
FatalError,
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace utils {
|
||||||
* // do rendering ...
|
* // do rendering ...
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
class DAWN_NO_DISCARD ScopedAutoreleasePool {
|
class [[nodiscard]] ScopedAutoreleasePool {
|
||||||
public:
|
public:
|
||||||
ScopedAutoreleasePool();
|
ScopedAutoreleasePool();
|
||||||
~ScopedAutoreleasePool();
|
~ScopedAutoreleasePool();
|
||||||
|
|
Loading…
Reference in New Issue