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>
diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp
index e473192..f463205 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 @@
         };
 
         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 @@
                                             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 bb2d669..3f5bd58 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 @@
 
 #    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 @@
 #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 @@
 #    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 0127a26..5537c84 100644
--- a/src/common/RefBase.h
+++ b/src/common/RefBase.h
@@ -134,7 +134,7 @@
         return mValue;
     }
 
-    T Detach() DAWN_NO_DISCARD {
+    [[nodiscard]] T Detach() {
         T value{std::move(mValue)};
         mValue = Traits::kNullValue;
         return value;
@@ -145,7 +145,7 @@
         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 4cea7f2..797f2d5 100644
--- a/src/common/Result.h
+++ b/src/common/Result.h
@@ -58,7 +58,7 @@
 // Specialization of Result for returning errors only via pointers. It is basically a pointer
 // where nullptr is both Success and Empty.
 template <typename E>
-class DAWN_NO_DISCARD Result<void, E> {
+class [[nodiscard]] Result<void, E> {
   public:
     Result();
     Result(std::unique_ptr<E> error);
@@ -109,7 +109,7 @@
 }  // namespace detail
 
 template <typename T, typename E>
-class DAWN_NO_DISCARD Result<T*, E> {
+class [[nodiscard]] Result<T*, E> {
   public:
     static_assert(alignof_if_defined_else_default<T, 4> >= 4,
                   "Result<T*, E*> reserves two bits for tagging pointers");
@@ -141,7 +141,7 @@
 };
 
 template <typename T, typename E>
-class DAWN_NO_DISCARD Result<const T*, E> {
+class [[nodiscard]] Result<const T*, E> {
   public:
     static_assert(alignof_if_defined_else_default<T, 4> >= 4,
                   "Result<T*, E*> reserves two bits for tagging pointers");
@@ -170,7 +170,7 @@
 class Ref;
 
 template <typename T, typename E>
-class DAWN_NO_DISCARD Result<Ref<T>, E> {
+class [[nodiscard]] Result<Ref<T>, E> {
   public:
     static_assert(alignof_if_defined_else_default<T, 4> >= 4,
                   "Result<Ref<T>, E> reserves two bits for tagging pointers");
@@ -205,7 +205,7 @@
 // a tagged union instead if it turns out to be a hotspot. T and E must be movable and default
 // constructible.
 template <typename T, typename E>
-class DAWN_NO_DISCARD Result {
+class [[nodiscard]] Result {
   public:
     Result(T&& success);
     Result(std::unique_ptr<E> error);
diff --git a/src/dawn_native/BindGroup.cpp b/src/dawn_native/BindGroup.cpp
index f447142..d125a59 100644
--- a/src/dawn_native/BindGroup.cpp
+++ b/src/dawn_native/BindGroup.cpp
@@ -217,7 +217,7 @@
                         "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 477a7e7..8dce44c 100644
--- a/src/dawn_native/ErrorData.h
+++ b/src/dawn_native/ErrorData.h
@@ -33,13 +33,11 @@
 namespace dawn_native {
     enum class InternalErrorType : uint32_t;
 
-    class DAWN_NO_DISCARD ErrorData {
+    class [[nodiscard]] ErrorData {
       public:
-        static DAWN_NO_DISCARD std::unique_ptr<ErrorData> Create(InternalErrorType type,
-                                                                 std::string message,
-                                                                 const char* file,
-                                                                 const char* function,
-                                                                 int line);
+        [[nodiscard]] static std::unique_ptr<ErrorData> 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 4168134..c669b2f 100644
--- a/src/dawn_native/d3d12/TextureD3D12.cpp
+++ b/src/dawn_native/d3d12/TextureD3D12.cpp
@@ -1275,7 +1275,7 @@
             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 f94fa50..e778282 100644
--- a/src/dawn_native/opengl/CommandBufferGL.cpp
+++ b/src/dawn_native/opengl/CommandBufferGL.cpp
@@ -756,7 +756,7 @@
                                 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 fc0deb3..0270739 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 e9c945d..bc587fa 100644
--- a/src/utils/ScopedAutoreleasePool.h
+++ b/src/utils/ScopedAutoreleasePool.h
@@ -41,7 +41,7 @@
      *     // do rendering ...
      *   }
      */
-    class DAWN_NO_DISCARD ScopedAutoreleasePool {
+    class [[nodiscard]] ScopedAutoreleasePool {
       public:
         ScopedAutoreleasePool();
         ~ScopedAutoreleasePool();