Replace DAWN_UNUSED with [[maybe_unused]]

Bug: none
Change-Id: Icbc2be46801018afb85d7c5e0e3b655c526fbb69
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/181722
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/generator/templates/dawn/fuzzers/lpmfuzz/DawnLPMSerializer.cpp b/generator/templates/dawn/fuzzers/lpmfuzz/DawnLPMSerializer.cpp
index 7d0e990..2a53c64 100644
--- a/generator/templates/dawn/fuzzers/lpmfuzz/DawnLPMSerializer.cpp
+++ b/generator/templates/dawn/fuzzers/lpmfuzz/DawnLPMSerializer.cpp
@@ -137,10 +137,8 @@
 
     WireResult {{WGPU}}{{name}}ProtoConvert(fuzzing::{{ name }} proto_record, {{WGPU}}{{ name }}{{ Cmd }} const *record, SerializeBuffer* serializeBuffer, PerObjectType<DawnLPMObjectStore> &objectStores) {
 
-        {{WGPU}}{{ name }}{{ Cmd }} *mutable_record = const_cast<{{WGPU}}{{ name }}{{ Cmd }} *>(record);
-
-        //* Some commands don't set any members.
-        DAWN_UNUSED(mutable_record);
+        //* maybe_unused because some commands don't set any members.
+        [[maybe_unused]] {{WGPU}}{{ name }}{{ Cmd }} *mutable_record = const_cast<{{WGPU}}{{ name }}{{ Cmd }} *>(record);
 
         //* Clear the entire structure to make optional handling simpler.
         memset(mutable_record, 0, sizeof({{WGPU}}{{ name }}{{ Cmd }}));
diff --git a/generator/templates/dawn/wire/WireCmd.cpp b/generator/templates/dawn/wire/WireCmd.cpp
index 9e63d7b..a62906e 100644
--- a/generator/templates/dawn/wire/WireCmd.cpp
+++ b/generator/templates/dawn/wire/WireCmd.cpp
@@ -176,8 +176,7 @@
     {% endif %}
 
     //* Returns the required transfer size for `record` in addition to the transfer structure.
-    DAWN_DECLARE_UNUSED size_t {{Return}}{{name}}GetExtraRequiredSize(const {{Return}}{{name}}{{Cmd}}& record) {
-        DAWN_UNUSED(record);
+    DAWN_DECLARE_UNUSED size_t {{Return}}{{name}}GetExtraRequiredSize([[maybe_unused]] const {{Return}}{{name}}{{Cmd}}& record) {
         size_t result = 0;
 
         //* Gather how much space will be needed for the extension chain.
@@ -242,12 +241,11 @@
     DAWN_DECLARE_UNUSED WireResult {{Return}}{{name}}Serialize(
         const {{Return}}{{name}}{{Cmd}}& record,
         {{Return}}{{name}}Transfer* transfer,
-        SerializeBuffer* buffer
+        [[maybe_unused]] SerializeBuffer* buffer
         {%- if record.may_have_dawn_object -%}
             , const ObjectIdProvider& provider
         {%- endif -%}
     ) {
-        DAWN_UNUSED(buffer);
         //* Handle special transfer members of methods.
         {% if is_cmd %}
             transfer->commandId = {{Return}}WireCmd::{{name}};
@@ -338,13 +336,11 @@
         {{Return}}{{name}}{{Cmd}}* record,
         const volatile {{Return}}{{name}}Transfer* transfer,
         DeserializeBuffer* deserializeBuffer,
-        DeserializeAllocator* allocator
+        [[maybe_unused]] DeserializeAllocator* allocator
         {%- if record.may_have_dawn_object -%}
             , const ObjectIdResolver& resolver
         {%- endif -%}
     ) {
-        DAWN_UNUSED(allocator);
-
         {% if is_cmd %}
             DAWN_ASSERT(transfer->commandId == {{Return}}WireCmd::{{name}});
         {% endif %}
diff --git a/src/dawn/common/Assert.h b/src/dawn/common/Assert.h
index d150132..1182883 100644
--- a/src/dawn/common/Assert.h
+++ b/src/dawn/common/Assert.h
@@ -88,7 +88,7 @@
 #else  // DAWN_COMPILER_IS(*)
 #define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
     do {                                                         \
-        DAWN_UNUSED(sizeof(condition));                          \
+        [[maybe_unused]] auto unused = sizeof(condition);        \
     } while (DAWN_ASSERT_LOOP_CONDITION)
 #endif  // DAWN_COMPILER_IS(*)
 
diff --git a/src/dawn/common/Compiler.h b/src/dawn/common/Compiler.h
index b1457ca..3299482 100644
--- a/src/dawn/common/Compiler.h
+++ b/src/dawn/common/Compiler.h
@@ -122,11 +122,6 @@
 #define DAWN_NO_SANITIZE(instrumentation)
 #endif
 
-// DAWN_UNUSED
-//
-// Prevents unused variable/expression warnings on EXPR.
-#define DAWN_UNUSED(EXPR) (void)EXPR
-
 // DAWN_UNUSED_FUNC
 //
 // Prevents unused variable/expression warnings on FUNC.
diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp
index c24f320..d7702b4 100644
--- a/src/dawn/native/Buffer.cpp
+++ b/src/dawn/native/Buffer.cpp
@@ -689,7 +689,8 @@
     if (GetDevice()->ConsumedError(ValidateUnmap(), "calling %s.Unmap().", this)) {
         return;
     }
-    DAWN_UNUSED(GetDevice()->ConsumedError(Unmap(), "calling %s.Unmap().", this));
+    [[maybe_unused]] bool hadError =
+        GetDevice()->ConsumedError(Unmap(), "calling %s.Unmap().", this);
 }
 
 MaybeError BufferBase::Unmap() {
diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp
index ec3b63a..c014fa0 100644
--- a/src/dawn/native/Device.cpp
+++ b/src/dawn/native/Device.cpp
@@ -1818,7 +1818,8 @@
 
     UnpackedPtr<TextureDescriptor> unpacked;
     if (!ConsumedError(ValidateAndUnpack(&rawDescriptor), &unpacked)) {
-        DAWN_UNUSED(ConsumedError(ValidateTextureDescriptor(this, unpacked, allowMultiPlanar)));
+        [[maybe_unused]] bool hadError =
+            ConsumedError(ValidateTextureDescriptor(this, unpacked, allowMultiPlanar));
     }
 }
 
diff --git a/src/dawn/native/Limits.cpp b/src/dawn/native/Limits.cpp
index 8c3b078..509e209 100644
--- a/src/dawn/native/Limits.cpp
+++ b/src/dawn/native/Limits.cpp
@@ -157,8 +157,7 @@
 
 template <uint32_t I, uint32_t... Is>
 constexpr uint32_t ReduceSameValue(std::integer_sequence<uint32_t, I, Is...>) {
-    int unused[] = {0, (StaticAssertSame<I, Is>(), 0)...};
-    DAWN_UNUSED(unused);
+    [[maybe_unused]] int unused[] = {0, (StaticAssertSame<I, Is>(), 0)...};
     return I;
 }
 
diff --git a/src/dawn/native/Queue.cpp b/src/dawn/native/Queue.cpp
index 7e061c4..bbeee41 100644
--- a/src/dawn/native/Queue.cpp
+++ b/src/dawn/native/Queue.cpp
@@ -287,9 +287,9 @@
         commands[i]->Destroy();
     }
 
-    DAWN_UNUSED(GetDevice()->ConsumedError(
+    [[maybe_unused]] bool hadError = GetDevice()->ConsumedError(
         std::move(result), "calling %s.Submit(%s)", this,
-        ityp::span<uint32_t, CommandBufferBase* const>(commands, commandCount)));
+        ityp::span<uint32_t, CommandBufferBase* const>(commands, commandCount));
 }
 
 void QueueBase::APIOnSubmittedWorkDone(WGPUQueueWorkDoneCallback callback, void* userdata) {
@@ -411,10 +411,10 @@
                                uint64_t bufferOffset,
                                const void* data,
                                size_t size) {
-    DAWN_UNUSED(
+    [[maybe_unused]] bool hadError =
         GetDevice()->ConsumedError(WriteBuffer(buffer, bufferOffset, data, size),
                                    "calling %s.WriteBuffer(%s, (%d bytes), data, (%d bytes))", this,
-                                   buffer, bufferOffset, size));
+                                   buffer, bufferOffset, size);
 }
 
 MaybeError QueueBase::WriteBuffer(BufferBase* buffer,
@@ -455,10 +455,10 @@
                                 size_t dataSize,
                                 const TextureDataLayout* dataLayout,
                                 const Extent3D* writeSize) {
-    DAWN_UNUSED(GetDevice()->ConsumedError(
+    [[maybe_unused]] bool hadError = GetDevice()->ConsumedError(
         WriteTextureInternal(destination, data, dataSize, *dataLayout, writeSize),
         "calling %s.WriteTexture(%s, (%u bytes), %s, %s)", this, destination, dataSize, dataLayout,
-        writeSize));
+        writeSize);
 }
 
 MaybeError QueueBase::WriteTextureInternal(const ImageCopyTexture* destinationOrig,
@@ -527,16 +527,16 @@
                                          const ImageCopyTexture* destination,
                                          const Extent3D* copySize,
                                          const CopyTextureForBrowserOptions* options) {
-    DAWN_UNUSED(GetDevice()->ConsumedError(
-        CopyTextureForBrowserInternal(source, destination, copySize, options)));
+    [[maybe_unused]] bool hadError = GetDevice()->ConsumedError(
+        CopyTextureForBrowserInternal(source, destination, copySize, options));
 }
 
 void QueueBase::APICopyExternalTextureForBrowser(const ImageCopyExternalTexture* source,
                                                  const ImageCopyTexture* destination,
                                                  const Extent3D* copySize,
                                                  const CopyTextureForBrowserOptions* options) {
-    DAWN_UNUSED(GetDevice()->ConsumedError(
-        CopyExternalTextureForBrowserInternal(source, destination, copySize, options)));
+    [[maybe_unused]] bool hadError = GetDevice()->ConsumedError(
+        CopyExternalTextureForBrowserInternal(source, destination, copySize, options));
 }
 
 MaybeError QueueBase::CopyTextureForBrowserInternal(const ImageCopyTexture* sourceOrig,
diff --git a/src/dawn/native/SharedFence.cpp b/src/dawn/native/SharedFence.cpp
index 3ba1c47..db223c1 100644
--- a/src/dawn/native/SharedFence.cpp
+++ b/src/dawn/native/SharedFence.cpp
@@ -66,7 +66,7 @@
 }
 
 void SharedFenceBase::APIExportInfo(SharedFenceExportInfo* info) const {
-    DAWN_UNUSED(GetDevice()->ConsumedError(ExportInfo(info)));
+    [[maybe_unused]] bool hadError = GetDevice()->ConsumedError(ExportInfo(info));
 }
 
 void SharedFenceBase::DestroyImpl() {}
diff --git a/src/dawn/native/SharedResourceMemory.cpp b/src/dawn/native/SharedResourceMemory.cpp
index ade989b..81eb653 100644
--- a/src/dawn/native/SharedResourceMemory.cpp
+++ b/src/dawn/native/SharedResourceMemory.cpp
@@ -168,16 +168,16 @@
 bool SharedResourceMemory::APIEndAccess(TextureBase* texture,
                                         SharedTextureMemoryEndAccessState* state) {
     bool didEnd = false;
-    DAWN_UNUSED(GetDevice()->ConsumedError(EndAccess(texture, state, &didEnd),
-                                           "calling %s.EndAccess(%s).", this, texture));
+    [[maybe_unused]] bool hadError = GetDevice()->ConsumedError(
+        EndAccess(texture, state, &didEnd), "calling %s.EndAccess(%s).", this, texture);
     return didEnd;
 }
 
 bool SharedResourceMemory::APIEndAccess(BufferBase* buffer,
                                         SharedBufferMemoryEndAccessState* state) {
     bool didEnd = false;
-    DAWN_UNUSED(GetDevice()->ConsumedError(EndAccess(buffer, state, &didEnd),
-                                           "calling %s.EndAccess(%s).", this, buffer));
+    [[maybe_unused]] bool hadError = GetDevice()->ConsumedError(
+        EndAccess(buffer, state, &didEnd), "calling %s.EndAccess(%s).", this, buffer);
     return didEnd;
 }
 
diff --git a/src/dawn/native/d3d/ExternalImageDXGIImpl.cpp b/src/dawn/native/d3d/ExternalImageDXGIImpl.cpp
index ff2aebe..531b331 100644
--- a/src/dawn/native/d3d/ExternalImageDXGIImpl.cpp
+++ b/src/dawn/native/d3d/ExternalImageDXGIImpl.cpp
@@ -133,9 +133,8 @@
     DAWN_ASSERT(mBackendDevice != nullptr);
     if (mBackendDevice->GetValidInternalFormat(mFormat).IsMultiPlanar() &&
         !descriptor->isInitialized) {
-        bool consumed = mBackendDevice->ConsumedError(DAWN_VALIDATION_ERROR(
+        [[maybe_unused]] bool consumed = mBackendDevice->ConsumedError(DAWN_VALIDATION_ERROR(
             "External textures with multiplanar formats must be initialized."));
-        DAWN_UNUSED(consumed);
         return nullptr;
     }
 
diff --git a/src/dawn/native/d3d11/CommandBufferD3D11.cpp b/src/dawn/native/d3d11/CommandBufferD3D11.cpp
index e337ed8..89e8cb7 100644
--- a/src/dawn/native/d3d11/CommandBufferD3D11.cpp
+++ b/src/dawn/native/d3d11/CommandBufferD3D11.cpp
@@ -907,7 +907,7 @@
         }
 
         case Command::PopDebugGroup: {
-            std::ignore = iter->NextCommand<PopDebugGroupCmd>();
+            [[maybe_unused]] auto cmd = iter->NextCommand<PopDebugGroupCmd>();
             commandContext->GetD3DUserDefinedAnnotation()->EndEvent();
             break;
         }
diff --git a/src/dawn/native/d3d12/CommandBufferD3D12.cpp b/src/dawn/native/d3d12/CommandBufferD3D12.cpp
index 90b329c..674ae04 100644
--- a/src/dawn/native/d3d12/CommandBufferD3D12.cpp
+++ b/src/dawn/native/d3d12/CommandBufferD3D12.cpp
@@ -822,10 +822,9 @@
                 Buffer* dstBuffer = ToBackend(copy->destination.Get());
 
                 DAWN_TRY(srcBuffer->EnsureDataInitialized(commandContext));
-                bool cleared;
+                [[maybe_unused]] bool cleared;
                 DAWN_TRY_ASSIGN(cleared, dstBuffer->EnsureDataInitializedAsDestination(
                                              commandContext, copy->destinationOffset, copy->size));
-                DAWN_UNUSED(cleared);
 
                 srcBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopySrc);
                 dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst);
@@ -1065,11 +1064,10 @@
                 Buffer* destination = ToBackend(cmd->destination.Get());
                 uint64_t destinationOffset = cmd->destinationOffset;
 
-                bool cleared;
+                [[maybe_unused]] bool cleared;
                 DAWN_TRY_ASSIGN(
                     cleared, destination->EnsureDataInitializedAsDestination(
                                  commandContext, destinationOffset, queryCount * sizeof(uint64_t)));
-                DAWN_UNUSED(cleared);
 
                 // Resolving unavailable queries is undefined behaviour on D3D12, we only can
                 // resolve the available part of sparse queries. In order to resolve the
@@ -1160,10 +1158,10 @@
                 DAWN_ASSERT(uploadHandle.mappedBuffer != nullptr);
                 memcpy(uploadHandle.mappedBuffer, data, size);
 
-                bool cleared;
+                [[maybe_unused]] bool cleared;
                 DAWN_TRY_ASSIGN(cleared, dstBuffer->EnsureDataInitializedAsDestination(
                                              commandContext, offset, size));
-                DAWN_UNUSED(cleared);
+
                 dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst);
                 commandList->CopyBufferRegion(
                     dstBuffer->GetD3D12Resource(), offset,
diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp
index e91368f..2bec840 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/DeviceD3D12.cpp
@@ -496,10 +496,9 @@
 
     Buffer* dstBuffer = ToBackend(destination);
 
-    bool cleared;
+    [[maybe_unused]] bool cleared;
     DAWN_TRY_ASSIGN(cleared, dstBuffer->EnsureDataInitializedAsDestination(
                                  commandRecordingContext, destinationOffset, size));
-    DAWN_UNUSED(cleared);
 
     CopyFromStagingToBufferHelper(commandRecordingContext, source, sourceOffset, destination,
                                   destinationOffset, size);
diff --git a/src/dawn/native/d3d12/ResidencyManagerD3D12.cpp b/src/dawn/native/d3d12/ResidencyManagerD3D12.cpp
index fc070d4..5a5234e 100644
--- a/src/dawn/native/d3d12/ResidencyManagerD3D12.cpp
+++ b/src/dawn/native/d3d12/ResidencyManagerD3D12.cpp
@@ -195,11 +195,9 @@
         return {};
     }
 
-    uint64_t bytesEvicted;
+    [[maybe_unused]] uint64_t bytesEvicted;
     DAWN_TRY_ASSIGN(bytesEvicted,
                     EnsureCanMakeResident(allocationSize, GetMemorySegmentInfo(memorySegment)));
-    DAWN_UNUSED(bytesEvicted);
-
     return {};
 }
 
@@ -310,9 +308,8 @@
                                                      uint64_t sizeToMakeResident,
                                                      uint64_t numberOfObjectsToMakeResident,
                                                      ID3D12Pageable** allocations) {
-    uint64_t bytesEvicted;
+    [[maybe_unused]] uint64_t bytesEvicted;
     DAWN_TRY_ASSIGN(bytesEvicted, EnsureCanMakeResident(sizeToMakeResident, segment));
-    DAWN_UNUSED(bytesEvicted);
 
     // Note that MakeResident is a synchronous function and can add a significant
     // overhead to command recording. In the future, it may be possible to decrease this
diff --git a/src/dawn/native/metal/BackendMTL.mm b/src/dawn/native/metal/BackendMTL.mm
index c4c8314..68a8b73 100644
--- a/src/dawn/native/metal/BackendMTL.mm
+++ b/src/dawn/native/metal/BackendMTL.mm
@@ -182,8 +182,7 @@
 
 #elif DAWN_PLATFORM_IS(IOS)
 
-MaybeError GetDevicePCIInfo(id<MTLDevice> device, PCIIDs* ids) {
-    DAWN_UNUSED(device);
+MaybeError GetDevicePCIInfo(id<MTLDevice>, PCIIDs* ids) {
     *ids = PCIIDs{0, 0};
     return {};
 }
diff --git a/src/dawn/native/vulkan/DeviceVk.cpp b/src/dawn/native/vulkan/DeviceVk.cpp
index 0df6422..d88ee8f 100644
--- a/src/dawn/native/vulkan/DeviceVk.cpp
+++ b/src/dawn/native/vulkan/DeviceVk.cpp
@@ -748,9 +748,8 @@
     }
     if (GetValidInternalFormat(textureDescriptor->format).IsMultiPlanar() &&
         !descriptor->isInitialized) {
-        bool consumed = ConsumedError(DAWN_VALIDATION_ERROR(
+        [[maybe_unused]] bool consumed = ConsumedError(DAWN_VALIDATION_ERROR(
             "External textures with multiplanar formats must be initialized."));
-        DAWN_UNUSED(consumed);
         return nullptr;
     }
 
diff --git a/src/dawn/native/vulkan/QueueVk.cpp b/src/dawn/native/vulkan/QueueVk.cpp
index 820b93d..1f32505 100644
--- a/src/dawn/native/vulkan/QueueVk.cpp
+++ b/src/dawn/native/vulkan/QueueVk.cpp
@@ -188,11 +188,11 @@
     Device* device = ToBackend(GetDevice());
     VkDevice vkDevice = device->GetVkDevice();
 
-    VkResult waitIdleResult = VkResult::WrapUnsafe(device->fn.QueueWaitIdle(mQueue));
     // Ignore the result of QueueWaitIdle: it can return OOM which we can't really do anything
     // about, Device lost, which means workloads running on the GPU are no longer accessible
     // (so they are as good as waited on) or success.
-    DAWN_UNUSED(waitIdleResult);
+    [[maybe_unused]] VkResult waitIdleResult =
+        VkResult::WrapUnsafe(device->fn.QueueWaitIdle(mQueue));
 
     // Make sure all fences are complete by explicitly waiting on them all
     mFencesInFlight.Use([&](auto fencesInFlight) {
diff --git a/src/dawn/native/vulkan/SwapChainVk.cpp b/src/dawn/native/vulkan/SwapChainVk.cpp
index b33764e..05191a5 100644
--- a/src/dawn/native/vulkan/SwapChainVk.cpp
+++ b/src/dawn/native/vulkan/SwapChainVk.cpp
@@ -53,14 +53,12 @@
 
 ResultOrError<VkSurfaceKHR> CreateVulkanSurface(const PhysicalDevice* physicalDevice,
                                                 const Surface* surface) {
-    const VulkanGlobalInfo& info = physicalDevice->GetVulkanInstance()->GetGlobalInfo();
-    const VulkanFunctions& fn = physicalDevice->GetVulkanInstance()->GetFunctions();
-    VkInstance instance = physicalDevice->GetVulkanInstance()->GetVkInstance();
-
     // May not be used in the platform-specific switches below.
-    DAWN_UNUSED(info);
-    DAWN_UNUSED(fn);
-    DAWN_UNUSED(instance);
+    [[maybe_unused]] const VulkanGlobalInfo& info =
+        physicalDevice->GetVulkanInstance()->GetGlobalInfo();
+    [[maybe_unused]] const VulkanFunctions& fn =
+        physicalDevice->GetVulkanInstance()->GetFunctions();
+    [[maybe_unused]] VkInstance instance = physicalDevice->GetVulkanInstance()->GetVkInstance();
 
     switch (surface->GetType()) {
 #if defined(DAWN_ENABLE_BACKEND_METAL)
diff --git a/src/dawn/native/vulkan/TextureVk.cpp b/src/dawn/native/vulkan/TextureVk.cpp
index 3b331f2..6700baf 100644
--- a/src/dawn/native/vulkan/TextureVk.cpp
+++ b/src/dawn/native/vulkan/TextureVk.cpp
@@ -952,7 +952,7 @@
     VkFormat format = VulkanImageFormat(device, GetFormat().format);
     VkImageUsageFlags usage = VulkanImageUsage(GetInternalUsage(), GetFormat());
 
-    bool supportsDisjoint;
+    [[maybe_unused]] bool supportsDisjoint;
     DAWN_INVALID_IF(
         !externalMemoryService->SupportsCreateImage(descriptor, format, usage, &supportsDisjoint),
         "Creating an image from external memory is not supported.");
@@ -960,7 +960,6 @@
     // the combined aspect without checking for disjoint support.
     // TODO(dawn:1548): Support multi-planar images with the DISJOINT feature and potentially allow
     // acting on planes individually? Always using Color is valid even for disjoint images.
-    DAWN_UNUSED(supportsDisjoint);
     DAWN_ASSERT(!GetFormat().IsMultiPlanar() || mCombinedAspect == Aspect::Color);
 
     mExternalState = ExternalState::PendingAcquire;
diff --git a/src/dawn/tests/perf_tests/DrawCallPerf.cpp b/src/dawn/tests/perf_tests/DrawCallPerf.cpp
index c06ea30..f5f0a3c 100644
--- a/src/dawn/tests/perf_tests/DrawCallPerf.cpp
+++ b/src/dawn/tests/perf_tests/DrawCallPerf.cpp
@@ -128,11 +128,10 @@
     DrawCallParamTuple paramTuple{Pipeline::Static, VertexBuffer::NoChange, BindGroup::NoChange,
                                   UniformData::Static, RenderBundle::No};
 
-    unsigned int unused[] = {
+    [[maybe_unused]] unsigned int unused[] = {
         0,  // Avoid making a 0-sized array.
         AssignParam(std::get<Ts>(paramTuple), args)...,
     };
-    DAWN_UNUSED(unused);
 
     return DrawCallParam{
         std::get<Pipeline>(paramTuple),     std::get<VertexBuffer>(paramTuple),
diff --git a/src/dawn/tests/unittests/BitSetIteratorTests.cpp b/src/dawn/tests/unittests/BitSetIteratorTests.cpp
index 0bccb75..615212b 100644
--- a/src/dawn/tests/unittests/BitSetIteratorTests.cpp
+++ b/src/dawn/tests/unittests/BitSetIteratorTests.cpp
@@ -68,8 +68,7 @@
     // We don't use the FAIL gtest macro here since it returns immediately,
     // causing an unreachable code warning in MSVC
     bool sawBit = false;
-    for (uint32_t bit : IterateBitSet(mStateBits)) {
-        DAWN_UNUSED(bit);
+    for ([[maybe_unused]] uint32_t bit : IterateBitSet(mStateBits)) {
         sawBit = true;
     }
     EXPECT_FALSE(sawBit);
@@ -136,8 +135,7 @@
     // We don't use the FAIL gtest macro here since it returns immediately,
     // causing an unreachable code warning in MSVC
     bool sawBit = false;
-    for (TestEnum bit : IterateBitSet(mStateBits)) {
-        DAWN_UNUSED(bit);
+    for ([[maybe_unused]] TestEnum bit : IterateBitSet(mStateBits)) {
         sawBit = true;
     }
     EXPECT_FALSE(sawBit);
@@ -202,8 +200,7 @@
     // We don't use the FAIL gtest macro here since it returns immediately,
     // causing an unreachable code warning in MSVC
     bool sawBit = false;
-    for (IntegerT bit : IterateBitSet(mStateBits)) {
-        DAWN_UNUSED(bit);
+    for ([[maybe_unused]] IntegerT bit : IterateBitSet(mStateBits)) {
         sawBit = true;
     }
     EXPECT_FALSE(sawBit);
diff --git a/src/dawn/tests/unittests/EnumMaskIteratorTests.cpp b/src/dawn/tests/unittests/EnumMaskIteratorTests.cpp
index 9430251..04f81e5 100644
--- a/src/dawn/tests/unittests/EnumMaskIteratorTests.cpp
+++ b/src/dawn/tests/unittests/EnumMaskIteratorTests.cpp
@@ -54,9 +54,12 @@
 static_assert(EnumBitmaskSize<TestAspect>::value == 3);
 
 TEST(EnumMaskIteratorTests, None) {
-    for (TestAspect aspect : IterateEnumMask(static_cast<TestAspect>(0))) {
+    for ([[maybe_unused]] TestAspect aspect : IterateEnumMask(static_cast<TestAspect>(0))) {
+        // Silence a -Wunreachable-code-loop-increment
+        if ((0)) {
+            continue;
+        }
         FAIL();
-        DAWN_UNUSED(aspect);
     }
 }
 
diff --git a/src/dawn/tests/unittests/EnumeratorTests.cpp b/src/dawn/tests/unittests/EnumeratorTests.cpp
index c20db30..d7d8b85 100644
--- a/src/dawn/tests/unittests/EnumeratorTests.cpp
+++ b/src/dawn/tests/unittests/EnumeratorTests.cpp
@@ -52,9 +52,7 @@
 
     template <typename Thing>
     void CheckEmpty(Thing thingToEnumerate) {
-        for (auto [index, value] : Enumerate(thingToEnumerate)) {
-            DAWN_UNUSED(index);
-            DAWN_UNUSED(value);
+        for ([[maybe_unused]] auto [index, value] : Enumerate(thingToEnumerate)) {
             FAIL();
         }
     }
diff --git a/src/dawn/tests/unittests/ErrorTests.cpp b/src/dawn/tests/unittests/ErrorTests.cpp
index f476143..9b25c9e 100644
--- a/src/dawn/tests/unittests/ErrorTests.cpp
+++ b/src/dawn/tests/unittests/ErrorTests.cpp
@@ -180,9 +180,8 @@
     };
 
     auto Try = [ReturnError]() -> ResultOrError<int*> {
-        int* result = nullptr;
+        [[maybe_unused]] int* result = nullptr;
         DAWN_TRY_ASSIGN(result, ReturnError());
-        DAWN_UNUSED(result);
 
         // DAWN_TRY should return before this point
         EXPECT_FALSE(true);
@@ -236,9 +235,8 @@
     };
 
     auto Try = [ReturnError]() -> MaybeError {
-        int* result = nullptr;
+        [[maybe_unused]] int* result = nullptr;
         DAWN_TRY_ASSIGN(result, ReturnError());
-        DAWN_UNUSED(result);
 
         return {};
     };
@@ -258,9 +256,8 @@
     };
 
     auto Try = [ReturnError]() -> MaybeError {
-        int result = 0;
+        [[maybe_unused]] int result = 0;
         DAWN_TRY_ASSIGN(result, ReturnError());
-        DAWN_UNUSED(result);
 
         return {};
     };
@@ -307,9 +304,8 @@
     bool tryCleanup = false;
 
     auto Try = [ReturnError, &tryCleanup]() -> ResultOrError<int*> {
-        int* result = nullptr;
+        [[maybe_unused]] int* result = nullptr;
         DAWN_TRY_ASSIGN_WITH_CLEANUP(result, ReturnError(), { tryCleanup = true; });
-        DAWN_UNUSED(result);
 
         // DAWN_TRY_ASSIGN_WITH_CLEANUP should return before this point
         EXPECT_FALSE(true);
@@ -331,9 +327,8 @@
     };
 
     auto Try = [ReturnError]() -> bool {
-        int* result = nullptr;
+        [[maybe_unused]] int* result = nullptr;
         DAWN_TRY_ASSIGN_WITH_CLEANUP(result, ReturnError(), {}, true);
-        DAWN_UNUSED(result);
 
         // DAWN_TRY_ASSIGN_WITH_CLEANUP should return before this point
         EXPECT_FALSE(true);
diff --git a/src/dawn/tests/unittests/RangeTests.cpp b/src/dawn/tests/unittests/RangeTests.cpp
index 0f0dd9d..5a34bfe 100644
--- a/src/dawn/tests/unittests/RangeTests.cpp
+++ b/src/dawn/tests/unittests/RangeTests.cpp
@@ -35,20 +35,18 @@
 
 // Test that iterating an empty range doesn't iterate at all.
 TEST(RangeTests, Empty) {
-    for (auto i : Range(0)) {
+    for ([[maybe_unused]] auto i : Range(0)) {
         // Silence a -Wunreachable-code-loop-increment
         if ((0)) {
             continue;
         }
-        DAWN_UNUSED(i);
         FAIL();
     }
-    for (auto i : Range(0, 0)) {
+    for ([[maybe_unused]] auto i : Range(0, 0)) {
         // Silence a -Wunreachable-code-loop-increment
         if ((0)) {
             continue;
         }
-        DAWN_UNUSED(i);
         FAIL();
     }
 }
diff --git a/src/dawn/tests/unittests/RefBaseTests.cpp b/src/dawn/tests/unittests/RefBaseTests.cpp
index 94b3a16..ee70d2f 100644
--- a/src/dawn/tests/unittests/RefBaseTests.cpp
+++ b/src/dawn/tests/unittests/RefBaseTests.cpp
@@ -133,7 +133,7 @@
     Ref ref(tracker);
 
     events.clear();
-    { DAWN_UNUSED(ref.Detach()); }
+    { [[maybe_unused]] auto ptr = ref.Detach(); }
     EXPECT_THAT(events, testing::ElementsAre(Event{Action::kAssign, 1, 0}  // nullify ref
                                              ));
 }
diff --git a/src/dawn/tests/unittests/SerialMapTests.cpp b/src/dawn/tests/unittests/SerialMapTests.cpp
index 8776ee6..68e956a 100644
--- a/src/dawn/tests/unittests/SerialMapTests.cpp
+++ b/src/dawn/tests/unittests/SerialMapTests.cpp
@@ -45,8 +45,7 @@
     ASSERT_TRUE(map.Empty());
 
     // Iterating on empty map 1) works 2) doesn't produce any values
-    for (int value : map.IterateAll()) {
-        DAWN_UNUSED(value);
+    for ([[maybe_unused]] int value : map.IterateAll()) {
         ASSERT_TRUE(false);
     }
 
@@ -68,8 +67,7 @@
     map.Clear();
     ASSERT_TRUE(map.Empty());
 
-    for (int value : map.IterateAll()) {
-        DAWN_UNUSED(value);
+    for ([[maybe_unused]] int value : map.IterateAll()) {
         ASSERT_TRUE(false);
     }
 }
diff --git a/src/dawn/tests/unittests/SerialQueueTests.cpp b/src/dawn/tests/unittests/SerialQueueTests.cpp
index 5fd5b7a..f785889 100644
--- a/src/dawn/tests/unittests/SerialQueueTests.cpp
+++ b/src/dawn/tests/unittests/SerialQueueTests.cpp
@@ -45,8 +45,7 @@
     ASSERT_TRUE(queue.Empty());
 
     // Iterating on empty queue 1) works 2) doesn't produce any values
-    for (int value : queue.IterateAll()) {
-        DAWN_UNUSED(value);
+    for ([[maybe_unused]] int value : queue.IterateAll()) {
         ASSERT_TRUE(false);
     }
 
@@ -68,8 +67,7 @@
     queue.Clear();
     ASSERT_TRUE(queue.Empty());
 
-    for (int value : queue.IterateAll()) {
-        DAWN_UNUSED(value);
+    for ([[maybe_unused]] int value : queue.IterateAll()) {
         ASSERT_TRUE(false);
     }
 }
diff --git a/src/dawn/tests/unittests/UnicodeTests.cpp b/src/dawn/tests/unittests/UnicodeTests.cpp
index 3c53dc5..dcfe73c 100644
--- a/src/dawn/tests/unittests/UnicodeTests.cpp
+++ b/src/dawn/tests/unittests/UnicodeTests.cpp
@@ -84,7 +84,7 @@
         native::ResultOrError<uint64_t> resultOrError =
             native::CountUTF16CodeUnitsFromUTF8String(std::string_view(testCase));
         ASSERT_TRUE(resultOrError.IsError());
-        std::ignore = resultOrError.AcquireError();
+        [[maybe_unused]] auto err = resultOrError.AcquireError();
     }
 }
 
diff --git a/src/dawn/wire/client/Buffer.cpp b/src/dawn/wire/client/Buffer.cpp
index af40829..1caaf47 100644
--- a/src/dawn/wire/client/Buffer.cpp
+++ b/src/dawn/wire/client/Buffer.cpp
@@ -356,8 +356,8 @@
     }
 
     if (mPendingMapRequest) {
-        DAWN_UNUSED(GetEventManager().SetFutureReady<MapAsyncEvent>(
-            futureIDInternal, WGPUBufferMapAsyncStatus_MappingAlreadyPending));
+        [[maybe_unused]] auto id = GetEventManager().SetFutureReady<MapAsyncEvent>(
+            futureIDInternal, WGPUBufferMapAsyncStatus_MappingAlreadyPending);
         return {futureIDInternal};
     }