diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp index e473192898..f463205baf 100644 --- a/generator/templates/dawn_wire/WireCmd.cpp +++ b/generator/templates/dawn_wire/WireCmd.cpp @@ -530,7 +530,7 @@ return result; } - DAWN_NO_DISCARD WireResult SerializeChainedStruct({{ChainedStructPtr}} chainedStruct, + [[nodiscard]] WireResult SerializeChainedStruct({{ChainedStructPtr}} chainedStruct, SerializeBuffer* buffer, const ObjectIdProvider& provider) { ASSERT(chainedStruct != nullptr); @@ -702,7 +702,7 @@ namespace dawn_wire { }; size_t GetChainedStructExtraRequiredSize(const WGPUChainedStruct* chainedStruct); - DAWN_NO_DISCARD WireResult SerializeChainedStruct(const WGPUChainedStruct* chainedStruct, + [[nodiscard]] WireResult SerializeChainedStruct(const WGPUChainedStruct* chainedStruct, SerializeBuffer* buffer, const ObjectIdProvider& provider); WireResult DeserializeChainedStruct(const WGPUChainedStruct** outChainNext, @@ -711,7 +711,7 @@ namespace dawn_wire { const ObjectIdResolver& resolver); size_t GetChainedStructExtraRequiredSize(WGPUChainedStructOut* chainedStruct); - DAWN_NO_DISCARD WireResult SerializeChainedStruct(WGPUChainedStructOut* chainedStruct, + [[nodiscard]] WireResult SerializeChainedStruct(WGPUChainedStructOut* chainedStruct, SerializeBuffer* buffer, const ObjectIdProvider& provider); WireResult DeserializeChainedStruct(WGPUChainedStructOut** outChainNext, diff --git a/src/common/Compiler.h b/src/common/Compiler.h index bb2d669857..3f5bd588d6 100644 --- a/src/common/Compiler.h +++ b/src/common/Compiler.h @@ -19,7 +19,6 @@ // - DAWN_COMPILER_[CLANG|GCC|MSVC]: Compiler detection // - DAWN_BREAKPOINT(): Raises an exception and breaks in the debugger // - 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 // (resp. false) to help it generate code that leads to better branch prediction. // - DAWN_UNUSED(EXPR): Prevents unused variable/expression warnings on EXPR. @@ -51,15 +50,6 @@ # define __has_cpp_attribute(name) 0 # 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)) # if defined(NDEBUG) # define DAWN_FORCE_INLINE inline __attribute__((always_inline)) @@ -75,11 +65,6 @@ extern void __cdecl __debugbreak(void); # 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 # if defined(NDEBUG) # define DAWN_FORCE_INLINE __forceinline @@ -102,9 +87,6 @@ extern void __cdecl __debugbreak(void); #if !defined(DAWN_UNLIKELY) # define DAWN_UNLIKELY(X) X #endif -#if !defined(DAWN_NO_DISCARD) -# define DAWN_NO_DISCARD -#endif #if !defined(DAWN_FORCE_INLINE) # define DAWN_FORCE_INLINE inline #endif @@ -112,10 +94,4 @@ extern void __cdecl __debugbreak(void); # define DAWN_NOINLINE #endif -#if defined(__clang__) -# define DAWN_FALLTHROUGH [[clang::fallthrough]] -#else -# define DAWN_FALLTHROUGH -#endif - #endif // COMMON_COMPILER_H_ diff --git a/src/common/RefBase.h b/src/common/RefBase.h index 0127a26801..5537c84fc4 100644 --- a/src/common/RefBase.h +++ b/src/common/RefBase.h @@ -134,7 +134,7 @@ class RefBase { return mValue; } - T Detach() DAWN_NO_DISCARD { + [[nodiscard]] T Detach() { T value{std::move(mValue)}; mValue = Traits::kNullValue; return value; @@ -145,7 +145,7 @@ class RefBase { mValue = value; } - T* InitializeInto() DAWN_NO_DISCARD { + [[nodiscard]] T* InitializeInto() { ASSERT(mValue == Traits::kNullValue); return &mValue; } diff --git a/src/common/Result.h b/src/common/Result.h index 4cea7f2f92..797f2d547c 100644 --- a/src/common/Result.h +++ b/src/common/Result.h @@ -58,7 +58,7 @@ class Result; // Specialization of Result for returning errors only via pointers. It is basically a pointer // where nullptr is both Success and Empty. template -class DAWN_NO_DISCARD Result { +class [[nodiscard]] Result { public: Result(); Result(std::unique_ptr error); @@ -109,7 +109,7 @@ namespace detail { } // namespace detail template -class DAWN_NO_DISCARD Result { +class [[nodiscard]] Result { public: static_assert(alignof_if_defined_else_default >= 4, "Result reserves two bits for tagging pointers"); @@ -141,7 +141,7 @@ class DAWN_NO_DISCARD Result { }; template -class DAWN_NO_DISCARD Result { +class [[nodiscard]] Result { public: static_assert(alignof_if_defined_else_default >= 4, "Result reserves two bits for tagging pointers"); @@ -170,7 +170,7 @@ template class Ref; template -class DAWN_NO_DISCARD Result, E> { +class [[nodiscard]] Result, E> { public: static_assert(alignof_if_defined_else_default >= 4, "Result, E> reserves two bits for tagging pointers"); @@ -205,7 +205,7 @@ class DAWN_NO_DISCARD Result, E> { // a tagged union instead if it turns out to be a hotspot. T and E must be movable and default // constructible. template -class DAWN_NO_DISCARD Result { +class [[nodiscard]] Result { public: Result(T&& success); Result(std::unique_ptr error); diff --git a/src/dawn_native/BindGroup.cpp b/src/dawn_native/BindGroup.cpp index f447142258..d125a59d7c 100644 --- a/src/dawn_native/BindGroup.cpp +++ b/src/dawn_native/BindGroup.cpp @@ -217,7 +217,7 @@ namespace dawn_native { "Filtering sampler %s is incompatible with non-filtering sampler " "binding.", entry.sampler); - DAWN_FALLTHROUGH; + [[fallthrough]]; case wgpu::SamplerBindingType::Filtering: DAWN_INVALID_IF( entry.sampler->IsComparison(), diff --git a/src/dawn_native/ErrorData.h b/src/dawn_native/ErrorData.h index 477a7e721b..8dce44c152 100644 --- a/src/dawn_native/ErrorData.h +++ b/src/dawn_native/ErrorData.h @@ -33,13 +33,11 @@ namespace dawn { namespace dawn_native { enum class InternalErrorType : uint32_t; - class DAWN_NO_DISCARD ErrorData { + class [[nodiscard]] ErrorData { public: - static DAWN_NO_DISCARD std::unique_ptr Create(InternalErrorType type, - std::string message, - const char* file, - const char* function, - int line); + [[nodiscard]] static std::unique_ptr Create( + InternalErrorType type, std::string message, const char* file, const char* function, + int line); ErrorData(InternalErrorType type, std::string message); struct BacktraceRecord { diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index 41681349ad..c669b2f1ba 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -1275,7 +1275,7 @@ namespace dawn_native { namespace d3d12 { switch (descriptor->dimension) { case wgpu::TextureViewDimension::e2DArray: ASSERT(texture->GetArrayLayers() == 1); - DAWN_FALLTHROUGH; + [[fallthrough]]; case wgpu::TextureViewDimension::e2D: ASSERT(texture->GetDimension() == wgpu::TextureDimension::e2D); mSrvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMS; diff --git a/src/dawn_native/opengl/CommandBufferGL.cpp b/src/dawn_native/opengl/CommandBufferGL.cpp index f94fa50ea2..e778282828 100644 --- a/src/dawn_native/opengl/CommandBufferGL.cpp +++ b/src/dawn_native/opengl/CommandBufferGL.cpp @@ -756,7 +756,7 @@ namespace dawn_native { namespace opengl { break; } // Implementation for 2D array is the same as 3D. - DAWN_FALLTHROUGH; + [[fallthrough]]; } case wgpu::TextureDimension::e3D: { diff --git a/src/dawn_wire/WireResult.h b/src/dawn_wire/WireResult.h index fc0deb3c86..02707392bb 100644 --- a/src/dawn_wire/WireResult.h +++ b/src/dawn_wire/WireResult.h @@ -19,7 +19,7 @@ namespace dawn_wire { - enum class DAWN_NO_DISCARD WireResult { + enum class [[nodiscard]] WireResult{ Success, FatalError, }; diff --git a/src/utils/ScopedAutoreleasePool.h b/src/utils/ScopedAutoreleasePool.h index e9c945dd2e..bc587faea6 100644 --- a/src/utils/ScopedAutoreleasePool.h +++ b/src/utils/ScopedAutoreleasePool.h @@ -41,7 +41,7 @@ namespace utils { * // do rendering ... * } */ - class DAWN_NO_DISCARD ScopedAutoreleasePool { + class [[nodiscard]] ScopedAutoreleasePool { public: ScopedAutoreleasePool(); ~ScopedAutoreleasePool();