From eb3f0166f8bb05086004b8fa04cef57d148c55ab Mon Sep 17 00:00:00 2001 From: phosit Date: Wed, 21 May 2025 12:29:47 +0200 Subject: [PATCH] Prefer [[maybe_unused]] over UNUSED2 `[[maybe_unused]]` is in the C++ standard. --- source/lib/debug.h | 2 +- source/lib/debug_stl.cpp | 12 ++--- source/lib/file/archive/codec_zlib.cpp | 6 +-- source/lib/file/io/io.cpp | 9 +--- source/lib/ogl.cpp | 7 +-- source/lib/sysdep/arch/x86_x64/apic.cpp | 4 +- .../lib/sysdep/os/win/tests/test_wdbg_sym.h | 41 ++++++-------- source/lib/sysdep/os/win/wnuma.cpp | 8 +-- source/network/NMTCreator.h | 30 ++++------- source/network/NetMessageSim.cpp | 8 +-- source/ps/GameSetup/Paths.cpp | 3 +- source/ps/TouchInput.cpp | 6 +-- source/renderer/backend/gl/Buffer.cpp | 4 +- .../backend/gl/DeviceCommandContext.cpp | 53 ++++++------------- source/renderer/backend/gl/Framebuffer.cpp | 4 +- source/renderer/backend/gl/ShaderProgram.cpp | 3 +- source/scriptinterface/FunctionWrapper.h | 18 ++----- .../serialization/StdDeserializer.cpp | 4 +- .../simulation2/serialization/StdSerializer.h | 6 +-- source/soundmanager/scripting/SoundGroup.cpp | 15 ++---- .../Handlers/CameraCtrlHandlers.cpp | 4 +- .../GameInterface/Handlers/CinemaHandler.cpp | 3 +- .../Handlers/CommandHandlers.cpp | 3 -- .../Handlers/GraphicsSetupHandlers.cpp | 13 +---- .../GameInterface/Handlers/MessageHandler.h | 4 +- .../GameInterface/Handlers/MiscHandlers.cpp | 5 +- .../GameInterface/Handlers/ObjectHandlers.cpp | 4 -- 27 files changed, 83 insertions(+), 196 deletions(-) diff --git a/source/lib/debug.h b/source/lib/debug.h index 5a52707f24..720b4c1547 100644 --- a/source/lib/debug.h +++ b/source/lib/debug.h @@ -301,7 +301,7 @@ Status debug_WriteCrashlog(const char* text); * (we do not provide an MFC-style VERIFY macro because the distinction * between ENSURE and VERIFY is unclear. to always run code but only * check for success in debug builds without raising unused-variable warnings, - * use ASSERT + UNUSED2.) + * use [[maybe_unused]].) **/ #define ASSERT(expr) ENSURE(expr) #ifdef NDEBUG diff --git a/source/lib/debug_stl.cpp b/source/lib/debug_stl.cpp index 355dc9ea5d..74e0d7a35c 100644 --- a/source/lib/debug_stl.cpp +++ b/source/lib/debug_stl.cpp @@ -552,17 +552,11 @@ template bool get_container_info(const T& t, size_t size, size_t el_siz // return number of elements and an iterator (any data it needs is stored in // it_mem, which must hold DEBUG_STL_MAX_ITERATOR_SIZE bytes). // returns 0 on success or an StlContainerError. -Status debug_stl_get_container_info(const wchar_t* type_name, const u8* p, size_t size, - size_t el_size, size_t* el_count, DebugStlIterator* el_iterator, void* it_mem) +Status debug_stl_get_container_info([[maybe_unused]] const wchar_t* type_name, [[maybe_unused]] const u8* p, + [[maybe_unused]] size_t size, [[maybe_unused]] size_t el_size, [[maybe_unused]] size_t* el_count, + [[maybe_unused]] DebugStlIterator* el_iterator, [[maybe_unused]] void* it_mem) { #if MSC_VERSION - UNUSED2(type_name); - UNUSED2(p); - UNUSED2(size); - UNUSED2(el_size); - UNUSED2(el_count); - UNUSED2(el_iterator); - UNUSED2(it_mem); return ERR::STL_CNT_UNSUPPORTED; // NOWARN #else diff --git a/source/lib/file/archive/codec_zlib.cpp b/source/lib/file/archive/codec_zlib.cpp index a489d17c49..06499b520a 100644 --- a/source/lib/file/archive/codec_zlib.cpp +++ b/source/lib/file/archive/codec_zlib.cpp @@ -37,14 +37,12 @@ class Codec_ZLib : public ICodec { public: - u32 UpdateChecksum(u32 checksum, const u8* in, size_t inSize) const + u32 UpdateChecksum([[maybe_unused]] u32 checksum, [[maybe_unused]] const u8* in, + [[maybe_unused]] size_t inSize) const { #if CODEC_COMPUTE_CHECKSUM return (u32)crc32(checksum, in, (uInt)inSize); #else - UNUSED2(checksum); - UNUSED2(in); - UNUSED2(inSize); return 0; #endif } diff --git a/source/lib/file/io/io.cpp b/source/lib/file/io/io.cpp index 886321a61e..542d9f6940 100644 --- a/source/lib/file/io/io.cpp +++ b/source/lib/file/io/io.cpp @@ -39,7 +39,7 @@ namespace io { // note that the Windows aio implementation requires buffers, sizes and // offsets to be sector-aligned. -Status Issue(aiocb& cb, size_t queueDepth) +Status Issue(aiocb& cb, [[maybe_unused]] size_t queueDepth) { #if CONFIG2_FILE_ENABLE_AIO if(queueDepth > 1) @@ -49,8 +49,6 @@ Status Issue(aiocb& cb, size_t queueDepth) WARN_RETURN(StatusFromErrno()); } else -#else - UNUSED2(queueDepth); #endif { ENSURE(lseek(cb.aio_fildes, cb.aio_offset, SEEK_SET) == cb.aio_offset); @@ -67,7 +65,7 @@ Status Issue(aiocb& cb, size_t queueDepth) } -Status WaitUntilComplete(aiocb& cb, size_t queueDepth) +Status WaitUntilComplete([[maybe_unused]] aiocb& cb, [[maybe_unused]] size_t queueDepth) { #if CONFIG2_FILE_ENABLE_AIO if(queueDepth > 1) @@ -94,9 +92,6 @@ SUSPEND_AGAIN: } cb.aio_nbytes = (size_t)bytesTransferred; } -#else - UNUSED2(cb); - UNUSED2(queueDepth); #endif return INFO::OK; diff --git a/source/lib/ogl.cpp b/source/lib/ogl.cpp index 24ee50b979..2ff28ca4c4 100644 --- a/source/lib/ogl.cpp +++ b/source/lib/ogl.cpp @@ -24,7 +24,6 @@ #include "lib/ogl.h" -#include "lib/code_annotation.h" #include "lib/config2.h" #include "lib/debug.h" #include "lib/external_libraries/libsdl.h" @@ -518,7 +517,7 @@ bool ogl_Init(void* (load)(const char*)) void ogl_SetVsyncEnabled(bool enabled) { - const int interval = enabled ? 1 : 0; + [[maybe_unused]] const int interval = enabled ? 1 : 0; #if !CONFIG2_GLES && OS_WIN if (ogl_HaveExtension("WGL_EXT_swap_control")) wglSwapIntervalEXT(interval); @@ -526,10 +525,6 @@ void ogl_SetVsyncEnabled(bool enabled) #if defined(SDL_VIDEO_DRIVER_X11) if (GLXVersion && ogl_HaveExtension("GLX_SGI_swap_control")) glXSwapIntervalSGI(interval); -#else - UNUSED2(interval); #endif -#else - UNUSED2(interval); #endif } diff --git a/source/lib/sysdep/arch/x86_x64/apic.cpp b/source/lib/sysdep/arch/x86_x64/apic.cpp index 2fa12c6f44..8b8d90e1fb 100644 --- a/source/lib/sysdep/arch/x86_x64/apic.cpp +++ b/source/lib/sysdep/arch/x86_x64/apic.cpp @@ -37,8 +37,8 @@ ApicId GetApicId() regs.eax = 1; // note: CPUID function 1 is always supported, but only processors with // an xAPIC (e.g. P4/Athlon XP) will return a nonzero ID. - bool ok = x86_x64::cpuid(®s); - ASSERT(ok); UNUSED2(ok); + [[maybe_unused]] bool ok = x86_x64::cpuid(®s); + ASSERT(ok); const u8 apicId = (u8)bits(regs.ebx, 24, 31); return apicId; } diff --git a/source/lib/sysdep/os/win/tests/test_wdbg_sym.h b/source/lib/sysdep/os/win/tests/test_wdbg_sym.h index 901f385acd..9c1d09948e 100644 --- a/source/lib/sysdep/os/win/tests/test_wdbg_sym.h +++ b/source/lib/sysdep/os/win/tests/test_wdbg_sym.h @@ -138,15 +138,15 @@ class TestWdbgSym : public CxxTest::TestSuite char s3; } Small; - Small small__ = { 0x55, 0xaa, -1 }; UNUSED2(small__); + [[maybe_unused]] Small small__ = { 0x55, 0xaa, -1 }; struct Large { u8 large_member_u8; std::string large_member_string; double large_member_double; - } - large = { 0xff, "large struct string", 123456.0 }; UNUSED2(large); + }; + [[maybe_unused]] Large large = { 0xff, "large struct string", 123456.0 }; class Base @@ -235,14 +235,15 @@ class TestWdbgSym : public CxxTest::TestSuite // also exercises all basic types because we need to display some values // anyway (to see at a glance whether symbol engine addrs are correct) - static void m_test_addrs(int p_int, double p_double, char* p_pchar, uintptr_t p_uintptr) + static void m_test_addrs([[maybe_unused]] int p_int, [[maybe_unused]] double p_double, + [[maybe_unused]] char* p_pchar, [[maybe_unused]] uintptr_t p_uintptr) { - size_t l_uint = 0x1234; - bool l_bool = true; UNUSED2(l_bool); - wchar_t l_wchars[] = L"wchar string"; - enum TestEnum { VAL1=1, VAL2=2 } l_enum = VAL1; - u8 l_u8s[] = { 1,2,3,4 }; - void (*l_funcptr)(void) = m_test_stl; + [[maybe_unused]] size_t l_uint = 0x1234; + [[maybe_unused]] bool l_bool = true; + [[maybe_unused]] wchar_t l_wchars[] = L"wchar string"; + [[maybe_unused]] enum TestEnum { VAL1=1, VAL2=2 } l_enum = VAL1; + [[maybe_unused]] u8 l_u8s[] = { 1,2,3,4 }; + [[maybe_unused]] void (*l_funcptr)(void) = m_test_stl; static double s_double = -2.718; static char s_chars[] = {'c','h','a','r','s',0}; @@ -262,25 +263,15 @@ class TestWdbgSym : public CxxTest::TestSuite debug_printf("l_enum addr=%p val=%d\n", &l_enum, l_enum); debug_printf("l_u8s addr=%p val=%d\n", &l_u8s, l_u8s); debug_printf("l_funcptr addr=%p val=%p\n", &l_funcptr, l_funcptr); -#else - UNUSED2(p_uintptr); - UNUSED2(p_pchar); - UNUSED2(p_double); - UNUSED2(p_int); - UNUSED2(l_funcptr); - UNUSED2(l_enum); - UNUSED2(l_uint); - UNUSED2(l_u8s); - UNUSED2(l_wchars); #endif m_test_stl(); - int uninit_int; UNUSED2(uninit_int); - float uninit_float; UNUSED2(uninit_float); - double uninit_double; UNUSED2(uninit_double); - bool uninit_bool; UNUSED2(uninit_bool); - HWND uninit_hwnd; UNUSED2(uninit_hwnd); + [[maybe_unused]] int uninit_int; + [[maybe_unused]] float uninit_float; + [[maybe_unused]] double uninit_double; + [[maybe_unused]] bool uninit_bool; + [[maybe_unused]] HWND uninit_hwnd; } #pragma optimize("", on) diff --git a/source/lib/sysdep/os/win/wnuma.cpp b/source/lib/sysdep/os/win/wnuma.cpp index cb5b58490f..7a4697d19a 100644 --- a/source/lib/sysdep/os/win/wnuma.cpp +++ b/source/lib/sysdep/os/win/wnuma.cpp @@ -473,7 +473,8 @@ bool numa_IsMemoryInterleaved() #if 0 -static bool VerifyPages(void* mem, size_t size, size_t pageSize, size_t node) +static bool VerifyPages([[maybe_unused]] void* mem, [[maybe_unused]] size_t size, + [[maybe_unused]] size_t pageSize, [[maybe_unused]] size_t node) { WUTIL_FUNC(pQueryWorkingSetEx, BOOL, (HANDLE, PVOID, DWORD)); WUTIL_IMPORT_KERNEL32(QueryWorkingSetEx, pQueryWorkingSetEx); @@ -510,11 +511,6 @@ static bool VerifyPages(void* mem, size_t size, size_t pageSize, size_t node) } delete[] wsi; -#else - UNUSED2(mem); - UNUSED2(size); - UNUSED2(pageSize); - UNUSED2(node); #endif return true; diff --git a/source/network/NMTCreator.h b/source/network/NMTCreator.h index 88ab6add32..8daf8daaba 100644 --- a/source/network/NMTCreator.h +++ b/source/network/NMTCreator.h @@ -146,15 +146,13 @@ public: \ size_t _nm::GetSerializedLength() const \ { \ size_t ret=_base::GetSerializedLength(); \ - const _nm *thiz=this;\ - UNUSED2(thiz); // preempt any "unused" warning + [[maybe_unused]] const _nm *thiz=this; #define NMT_START_ARRAY(_nm) \ std::vector ::const_iterator it=_nm.begin(); \ while (it != _nm.end()) \ { \ - const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it;\ - UNUSED2(thiz); // preempt any "unused" warning + [[maybe_unused]] const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it; #define NMT_END_ARRAY() \ ++it; \ @@ -191,15 +189,13 @@ u8 *_nm::Serialize(u8 *buffer) const \ { \ /*printf("In " #_nm "::Serialize()\n");*/ \ u8 *pos=_base::Serialize(buffer); \ - const _nm *thiz=this;\ - UNUSED2(thiz); // preempt any "unused" warning + [[maybe_unused]] const _nm *thiz=this; #define NMT_START_ARRAY(_nm) \ std::vector ::const_iterator it=_nm.begin(); \ while (it != _nm.end()) \ { \ - const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it;\ - UNUSED2(thiz); // preempt any "unused" warning + [[maybe_unused]] const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it; #define NMT_END_ARRAY() \ ++it; \ @@ -239,16 +235,15 @@ const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \ { \ pos=_base::Deserialize(pos, end); \ if (pos == NULL) BAIL_DESERIALIZER;\ - _nm *thiz=this; \ - /*printf("In Deserialize" #_nm "\n"); */\ - UNUSED2(thiz); // preempt any "unused" warning + [[maybe_unused]] _nm *thiz=this; \ + /*printf("In Deserialize" #_nm "\n"); */ #define NMT_START_ARRAY(_nm) \ while (pos < end) \ { \ - ARRAY_STRUCT_PREFIX(_nm) *thiz=&*_nm.insert(_nm.end(), ARRAY_STRUCT_PREFIX(_nm)());\ - UNUSED2(thiz); // preempt any "unused" warning + [[maybe_unused]] ARRAY_STRUCT_PREFIX(_nm) *thiz = \ + &*_nm.insert(_nm.end(), ARRAY_STRUCT_PREFIX(_nm)()); #define NMT_END_ARRAY() \ } @@ -289,8 +284,7 @@ CStr _nm::ToString() const \ CStr _nm::ToStringRaw() const \ { \ CStr ret; \ - const _nm *thiz=this;\ - UNUSED2(thiz); // preempt any "unused" warning + [[maybe_unused]] const _nm *thiz=this; #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ CStr _nm::ToString() const \ @@ -301,8 +295,7 @@ CStr _nm::ToString() const \ CStr _nm::ToStringRaw() const \ { \ CStr ret=_base::ToStringRaw() + ", "; \ - const _nm *thiz=this;\ - UNUSED2(thiz); // preempt any "unused" warning + [[maybe_unused]] const _nm *thiz=this; #define NMT_START_ARRAY(_nm) \ ret+=#_nm ": { "; \ @@ -310,8 +303,7 @@ CStr _nm::ToStringRaw() const \ while (it != _nm.end()) \ { \ ret+=" { "; \ - const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it;\ - UNUSED2(thiz); // preempt any "unused" warning + [[maybe_unused]] const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it; #define NMT_END_ARRAY() \ ++it; \ diff --git a/source/network/NetMessageSim.cpp b/source/network/NetMessageSim.cpp index a0c4209c47..098593206c 100644 --- a/source/network/NetMessageSim.cpp +++ b/source/network/NetMessageSim.cpp @@ -46,7 +46,7 @@ public: { } - void Put(const char* name, const u8* data, size_t len) + void Put([[maybe_unused]] const char* name, const u8* data, size_t len) { #if DEBUG_SERIALIZER_ANNOTATE std::string tag = "<"; @@ -54,8 +54,6 @@ public: tag.append(">"); memcpy(m_Buffer, tag.c_str(), tag.length()); m_Buffer += tag.length(); - #else - UNUSED2(name); #endif memcpy(m_Buffer, data, len); m_Buffer += len; @@ -89,13 +87,11 @@ public: { } - void Put(const char* name, const u8* /*data*/, size_t len) + void Put([[maybe_unused]] const char* name, const u8* /*data*/, size_t len) { #if DEBUG_SERIALIZER_ANNOTATE m_Length += 2; // '<' and '>' m_Length += strlen(name); - #else - UNUSED2(name); #endif m_Length += len; } diff --git a/source/ps/GameSetup/Paths.cpp b/source/ps/GameSetup/Paths.cpp index 9afba58b2b..22549bd760 100644 --- a/source/ps/GameSetup/Paths.cpp +++ b/source/ps/GameSetup/Paths.cpp @@ -184,11 +184,10 @@ Paths::Paths(const CmdLineArgs& args) #endif } -/*static*/ OsPath Paths::RootData(const OsPath& argv0) +/*static*/ OsPath Paths::RootData([[maybe_unused]] const OsPath& argv0) { #ifdef INSTALLED_DATADIR - UNUSED2(argv0); return OsPath(STRINGIZE(INSTALLED_DATADIR))/""; #else diff --git a/source/ps/TouchInput.cpp b/source/ps/TouchInput.cpp index 07d57f4a70..18d386bdea 100644 --- a/source/ps/TouchInput.cpp +++ b/source/ps/TouchInput.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2024 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -182,10 +182,8 @@ void CTouchInput::Frame() } } -InReaction CTouchInput::HandleEvent(const SDL_Event_* ev) +InReaction CTouchInput::HandleEvent([[maybe_unused]] const SDL_Event_* ev) { - UNUSED2(ev); // may be unused depending on #ifs - if (!IsEnabled()) return IN_PASS; diff --git a/source/renderer/backend/gl/Buffer.cpp b/source/renderer/backend/gl/Buffer.cpp index 930c660e38..1d69bfaf1a 100644 --- a/source/renderer/backend/gl/Buffer.cpp +++ b/source/renderer/backend/gl/Buffer.cpp @@ -59,7 +59,7 @@ GLenum GetTargetFromBufferType(const IBuffer::Type type) // static std::unique_ptr CBuffer::Create( - CDevice* device, const char* name, + CDevice* device, [[maybe_unused]] const char* name, const Type type, const uint32_t size, const uint32_t usage) { ENSURE(type == Type::VERTEX || type == Type::INDEX || type == Type::UNIFORM); @@ -77,8 +77,6 @@ std::unique_ptr CBuffer::Create( { glObjectLabel(GL_BUFFER, buffer->m_Handle, -1, name); } -#else - UNUSED2(name); #endif glBindBufferARB(target, 0); return buffer; diff --git a/source/renderer/backend/gl/DeviceCommandContext.cpp b/source/renderer/backend/gl/DeviceCommandContext.cpp index 073f220d4f..4dd0bec378 100644 --- a/source/renderer/backend/gl/DeviceCommandContext.cpp +++ b/source/renderer/backend/gl/DeviceCommandContext.cpp @@ -864,18 +864,13 @@ void CDeviceCommandContext::SetGraphicsPipelineStateImpl( void CDeviceCommandContext::BlitFramebuffer( IFramebuffer* srcFramebuffer, IFramebuffer* dstFramebuffer, - const Rect& sourceRegion, const Rect& destinationRegion, - const Sampler::Filter filter) + [[maybe_unused]] const Rect& sourceRegion, [[maybe_unused]] const Rect& destinationRegion, + [[maybe_unused]] const Sampler::Filter filter) { ENSURE(!m_InsideFramebufferPass); - CFramebuffer* destinationFramebuffer = dstFramebuffer->As(); - CFramebuffer* sourceFramebuffer = srcFramebuffer->As(); + [[maybe_unused]] CFramebuffer* destinationFramebuffer = dstFramebuffer->As(); + [[maybe_unused]] CFramebuffer* sourceFramebuffer = srcFramebuffer->As(); #if CONFIG2_GLES - UNUSED2(destinationFramebuffer); - UNUSED2(sourceFramebuffer); - UNUSED2(destinationRegion); - UNUSED2(sourceRegion); - UNUSED2(filter); debug_warn("CDeviceCommandContext::BlitFramebuffer is not implemented for GLES"); #else // Source framebuffer should not be backbuffer. @@ -1188,7 +1183,7 @@ void CDeviceCommandContext::DrawIndexed( } void CDeviceCommandContext::DrawInstanced( - const uint32_t firstVertex, const uint32_t vertexCount, + [[maybe_unused]] const uint32_t firstVertex, const uint32_t vertexCount, const uint32_t firstInstance, const uint32_t instanceCount) { ENSURE(m_Device->GetCapabilities().instancing); @@ -1200,7 +1195,6 @@ void CDeviceCommandContext::DrawInstanced( m_ShaderProgram->AssertPointersBound(); #if CONFIG2_GLES ENSURE(!m_Device->GetCapabilities().instancing); - UNUSED2(firstVertex); #else glDrawArraysInstancedARB(GL_TRIANGLES, firstVertex, vertexCount, instanceCount); #endif @@ -1209,7 +1203,7 @@ void CDeviceCommandContext::DrawInstanced( void CDeviceCommandContext::DrawIndexedInstanced( const uint32_t firstIndex, const uint32_t indexCount, - const uint32_t firstInstance, const uint32_t instanceCount, + const uint32_t firstInstance, [[maybe_unused]] const uint32_t instanceCount, const int32_t vertexOffset) { ENSURE(m_Device->GetCapabilities().instancing); @@ -1229,7 +1223,6 @@ void CDeviceCommandContext::DrawIndexedInstanced( // in Mesa 7.10 swrast with index VBOs). #if CONFIG2_GLES ENSURE(!m_Device->GetCapabilities().instancing); - UNUSED2(instanceCount); #else glDrawElementsInstancedARB(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, static_cast((static_cast(m_IndexBufferData) + sizeof(uint16_t) * firstIndex)), @@ -1240,7 +1233,7 @@ void CDeviceCommandContext::DrawIndexedInstanced( void CDeviceCommandContext::DrawIndexedInRange( const uint32_t firstIndex, const uint32_t indexCount, - const uint32_t start, const uint32_t end) + [[maybe_unused]] const uint32_t start, [[maybe_unused]] const uint32_t end) { ENSURE(m_ShaderProgram); ENSURE(m_InsidePass); @@ -1253,8 +1246,6 @@ void CDeviceCommandContext::DrawIndexedInRange( // Draw with DrawRangeElements where available, since it might be more // efficient for slow hardware. #if CONFIG2_GLES - UNUSED2(start); - UNUSED2(end); glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, indices); #else glDrawRangeElementsEXT(GL_TRIANGLES, start, end, indexCount, GL_UNSIGNED_SHORT, indices); @@ -1276,9 +1267,9 @@ void CDeviceCommandContext::EndComputePass() } void CDeviceCommandContext::Dispatch( - const uint32_t groupCountX, - const uint32_t groupCountY, - const uint32_t groupCountZ) + [[maybe_unused]] const uint32_t groupCountX, + [[maybe_unused]] const uint32_t groupCountY, + [[maybe_unused]] const uint32_t groupCountZ) { #if !CONFIG2_GLES ENSURE(m_InsideComputePass); @@ -1290,16 +1281,12 @@ void CDeviceCommandContext::Dispatch( glMemoryBarrier( GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL_TEXTURE_FETCH_BARRIER_BIT | GL_TEXTURE_UPDATE_BARRIER_BIT | GL_FRAMEBUFFER_BARRIER_BIT ); } -#else - UNUSED2(groupCountX); - UNUSED2(groupCountY); - UNUSED2(groupCountZ); #endif } void CDeviceCommandContext::InsertMemoryBarrier( - const uint32_t /*srcStageMask*/, const uint32_t dstStageMask, - const uint32_t srcAccessMask, const uint32_t dstAccessMask) + const uint32_t /*srcStageMask*/, [[maybe_unused]] const uint32_t dstStageMask, + [[maybe_unused]] const uint32_t srcAccessMask, [[maybe_unused]] const uint32_t dstAccessMask) { #if !CONFIG2_GLES ENSURE(!m_InsideFramebufferPass); @@ -1323,10 +1310,6 @@ void CDeviceCommandContext::InsertMemoryBarrier( } if (barriers) glMemoryBarrier(barriers); -#else - UNUSED2(dstStageMask); - UNUSED2(srcAccessMask); - UNUSED2(dstAccessMask); #endif } @@ -1372,7 +1355,8 @@ void CDeviceCommandContext::SetTexture(const int32_t bindingSlot, ITexture* text BindTexture(unit, textureUnit.target, texture->As()->GetHandle()); } -void CDeviceCommandContext::SetStorageTexture(const int32_t bindingSlot, ITexture* texture) +void CDeviceCommandContext::SetStorageTexture([[maybe_unused]] const int32_t bindingSlot, + [[maybe_unused]] ITexture* texture) { #if !CONFIG2_GLES ENSURE(m_ShaderProgram); @@ -1386,13 +1370,11 @@ void CDeviceCommandContext::SetStorageTexture(const int32_t bindingSlot, ITextur ENSURE(textureUnit.type == GL_IMAGE_2D); ENSURE(texture->GetFormat() == Format::R8G8B8A8_UNORM); glBindImageTexture(textureUnit.unit, texture->As()->GetHandle(), 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8); -#else - UNUSED2(bindingSlot); - UNUSED2(texture); #endif } -void CDeviceCommandContext::SetStorageBuffer(const int32_t bindingSlot, IBuffer* buffer) +void CDeviceCommandContext::SetStorageBuffer([[maybe_unused]] const int32_t bindingSlot, + [[maybe_unused]] IBuffer* buffer) { #if !CONFIG2_GLES if (bindingSlot < 0) @@ -1401,9 +1383,6 @@ void CDeviceCommandContext::SetStorageBuffer(const int32_t bindingSlot, IBuffer* ENSURE(buffer); ENSURE(buffer->GetUsage() & Renderer::Backend::IBuffer::Usage::STORAGE); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, m_ShaderProgram->GetStorageBuffer(bindingSlot), buffer->As()->GetHandle()); -#else - UNUSED2(bindingSlot); - UNUSED2(buffer); #endif } diff --git a/source/renderer/backend/gl/Framebuffer.cpp b/source/renderer/backend/gl/Framebuffer.cpp index fe1c0a7d3c..7019644b24 100644 --- a/source/renderer/backend/gl/Framebuffer.cpp +++ b/source/renderer/backend/gl/Framebuffer.cpp @@ -38,7 +38,7 @@ namespace GL // static std::unique_ptr CFramebuffer::Create( - CDevice* device, const char* name, SColorAttachment* colorAttachment, + CDevice* device, [[maybe_unused]] const char* name, SColorAttachment* colorAttachment, SDepthStencilAttachment* depthStencilAttachment) { ENSURE(colorAttachment || depthStencilAttachment); @@ -143,8 +143,6 @@ std::unique_ptr CFramebuffer::Create( { glObjectLabel(GL_FRAMEBUFFER, framebuffer->m_Handle, -1, name); } -#else - UNUSED2(name); #endif const GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); diff --git a/source/renderer/backend/gl/ShaderProgram.cpp b/source/renderer/backend/gl/ShaderProgram.cpp index d7bddc00f3..d67e879118 100644 --- a/source/renderer/backend/gl/ShaderProgram.cpp +++ b/source/renderer/backend/gl/ShaderProgram.cpp @@ -1254,7 +1254,7 @@ public: void VertexAttribPointer( const VertexAttributeStream stream, const Format format, const uint32_t offset, const uint32_t stride, - const VertexAttributeRate rate, const void* data) override + [[maybe_unused]] const VertexAttributeRate rate, const void* data) override { const int attributeLocation = GetAttributeLocationFromStream(m_Device, stream); std::vector::const_iterator it = @@ -1268,7 +1268,6 @@ public: attributeLocation, size, type, normalized, stride, static_cast(data) + offset); #if CONFIG2_GLES ENSURE(!m_Device->GetCapabilities().instancing); - UNUSED2(rate); #else if (rate == VertexAttributeRate::PER_INSTANCE) ENSURE(m_Device->GetCapabilities().instancing); diff --git a/source/scriptinterface/FunctionWrapper.h b/source/scriptinterface/FunctionWrapper.h index 1b237c16d0..58f38d73a5 100644 --- a/source/scriptinterface/FunctionWrapper.h +++ b/source/scriptinterface/FunctionWrapper.h @@ -104,7 +104,8 @@ private: * @param wentOk - true if the conversion succeeded and wentOk was true before, false otherwise. */ template - static T DoConvertFromJS(const ScriptRequest& rq, JS::CallArgs& args, bool& wentOk) + static T DoConvertFromJS([[maybe_unused]] const ScriptRequest& rq, + [[maybe_unused]] JS::CallArgs& args, [[maybe_unused]] bool& wentOk) { // No need to convert JS values. if constexpr (std::is_same_v) @@ -114,11 +115,7 @@ private: if (idx >= args.length()) return JS::UndefinedHandleValue; else - { - // GCC (at least < 9) & VS17 prints warnings if arguments are not used in some constexpr branch. - UNUSED2(rq); UNUSED2(args); UNUSED2(wentOk); return args[idx]; // This passes the null handle value if idx is beyond the length of args. - } } else { @@ -185,14 +182,10 @@ private: * Wrap std::apply for the case where we have an object method or a regular function. */ template - static typename args_info::return_type call(T* object, tuple& args) + static typename args_info::return_type call([[maybe_unused]] T* object, tuple& args) { if constexpr(std::is_same_v) - { - // GCC (at least < 9) & VS17 prints warnings if arguments are not used in some constexpr branch. - UNUSED2(object); return std::apply(callable, args); - } else return std::apply(callable, std::tuple_cat(std::forward_as_tuple(*object), args)); } @@ -224,7 +217,8 @@ private: * This could be worked around with more templates, but it doesn't seem particularly worth doing. */ template - static bool Call_(const ScriptRequest& rq, JS::HandleValue val, const char* name, R& ret, const Args&... args) + static bool Call_(const ScriptRequest& rq, JS::HandleValue val, const char* name, + [[maybe_unused]] R& ret, const Args&... args) { JS::RootedObject obj(rq.cx); if (!JS_ValueToObject(rq.cx, val, &obj) || !obj) @@ -251,8 +245,6 @@ private: if (success) success = Script::FromJSVal(rq, jsRet, ret); } - else - UNUSED2(ret); // VS2017 complains. } // Even if everything succeeded, there could be pending exceptions return !ScriptException::CatchPending(rq) && success; diff --git a/source/simulation2/serialization/StdDeserializer.cpp b/source/simulation2/serialization/StdDeserializer.cpp index 8e5ecca59a..46a372ef51 100644 --- a/source/simulation2/serialization/StdDeserializer.cpp +++ b/source/simulation2/serialization/StdDeserializer.cpp @@ -60,7 +60,7 @@ void CStdDeserializer::TraceMember(JSTracer *trc) JS::TraceEdge(trc, &backref, "StdDeserializer::m_ScriptBackrefs"); } -void CStdDeserializer::Get(const char* name, u8* data, size_t len) +void CStdDeserializer::Get([[maybe_unused]] const char* name, u8* data, size_t len) { #if DEBUG_SERIALIZER_ANNOTATE std::string strName; @@ -75,8 +75,6 @@ void CStdDeserializer::Get(const char* name, u8* data, size_t len) strName += c; } ENSURE(strName == name); -#else - UNUSED2(name); #endif m_Stream.read((char*)data, (std::streamsize)len); if (!m_Stream.good()) diff --git a/source/simulation2/serialization/StdSerializer.h b/source/simulation2/serialization/StdSerializer.h index b6445b5972..33067245b4 100644 --- a/source/simulation2/serialization/StdSerializer.h +++ b/source/simulation2/serialization/StdSerializer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -35,14 +35,12 @@ public: m_Stream.flush(); } - void Put(const char* name, const u8* data, size_t len) + void Put([[maybe_unused]] const char* name, const u8* data, size_t len) { #if DEBUG_SERIALIZER_ANNOTATE m_Stream.put('<'); m_Stream.write(name, strlen(name)); m_Stream.put('>'); -#else - UNUSED2(name); #endif m_Stream.write((const char*)data, (std::streamsize)len); } diff --git a/source/soundmanager/scripting/SoundGroup.cpp b/source/soundmanager/scripting/SoundGroup.cpp index 52800156cd..542c66aa47 100644 --- a/source/soundmanager/scripting/SoundGroup.cpp +++ b/source/soundmanager/scripting/SoundGroup.cpp @@ -128,12 +128,10 @@ CSoundGroup::~CSoundGroup() ReleaseGroup(); } -float CSoundGroup::RadiansOffCenter(const CVector3D& position, bool& onScreen, float& itemRollOff) +float CSoundGroup::RadiansOffCenter([[maybe_unused]] const CVector3D& position, + [[maybe_unused]] bool& onScreen, [[maybe_unused]] float& itemRollOff) { #if !CONFIG2_AUDIO - UNUSED2(position); - UNUSED2(onScreen); - UNUSED2(itemRollOff); return 0.f; #else const int screenWidth = g_Game->GetView()->GetCamera()->GetViewPort().m_Width; @@ -181,13 +179,10 @@ float CSoundGroup::RadiansOffCenter(const CVector3D& position, bool& onScreen, f #endif // !CONFIG2_AUDIO } -void CSoundGroup::UploadPropertiesAndPlay(size_t index, const CVector3D& position, entity_id_t source) +void CSoundGroup::UploadPropertiesAndPlay([[maybe_unused]] size_t index, + [[maybe_unused]] const CVector3D& position, [[maybe_unused]] entity_id_t source) { -#if !CONFIG2_AUDIO - UNUSED2(index); - UNUSED2(position); - UNUSED2(source); -#else +#if CONFIG2_AUDIO if (!g_SoundManager) return; diff --git a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp index 6130022079..8161f5c640 100644 --- a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2024 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -57,8 +57,6 @@ MESSAGEHANDLER(CameraReset) } g_Game->GetView()->ResetCameraTarget(target); - - UNUSED2(msg); } MESSAGEHANDLER(ScrollConstant) diff --git a/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp b/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp index 250c9e6c2c..c2e784d85a 100644 --- a/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2024 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -534,7 +534,6 @@ QUERYHANDLER(PickAxis) MESSAGEHANDLER(ClearPathNodePreview) { - UNUSED2(msg); g_AtlasGameLoop->view->SetParam(L"movetool", false); } diff --git a/source/tools/atlas/GameInterface/Handlers/CommandHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/CommandHandlers.cpp index 5f56eaed3f..d50aecca42 100644 --- a/source/tools/atlas/GameInterface/Handlers/CommandHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CommandHandlers.cpp @@ -43,19 +43,16 @@ MESSAGEHANDLER(DoCommand) MESSAGEHANDLER(UndoCommand) { - UNUSED2(msg); GetCommandProc().Undo(); } MESSAGEHANDLER(RedoCommand) { - UNUSED2(msg); GetCommandProc().Redo(); } MESSAGEHANDLER(MergeCommand) { - UNUSED2(msg); GetCommandProc().Merge(); } diff --git a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp index 7aa2251609..a2e08053d1 100644 --- a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2024 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -72,8 +72,6 @@ std::optional g_ScriptInterface; MESSAGEHANDLER(Init) { - UNUSED2(msg); - g_Quickstart = true; InitVfs(g_AtlasGameLoop->args); @@ -98,15 +96,11 @@ MESSAGEHANDLER(InitAppWindow) { #if OS_WIN wutil_SetAppWindow(msg->handle); -#else - UNUSED2(msg); #endif } MESSAGEHANDLER(InitSDL) { - UNUSED2(msg); - // When using GLX (Linux), SDL has to load the GL library to find // glXGetProcAddressARB before it can load any extensions. // When running in Atlas, we skip the SDL video initialisation code @@ -128,8 +122,6 @@ MESSAGEHANDLER(InitSDL) MESSAGEHANDLER(InitGraphics) { - UNUSED2(msg); - g_VideoMode.CreateBackendDevice(false); g_VideoMode.GetBackendDevice()->OnWindowResize(g_xres, g_yres); @@ -141,8 +133,6 @@ MESSAGEHANDLER(InitGraphics) MESSAGEHANDLER(Shutdown) { - UNUSED2(msg); - // Empty the CommandProc, to get rid of its references to entities before // we kill the EntityManager GetCommandProc().Destroy(); @@ -159,7 +149,6 @@ MESSAGEHANDLER(Shutdown) QUERYHANDLER(Exit) { - UNUSED2(msg); g_AtlasGameLoop->running = false; } diff --git a/source/tools/atlas/GameInterface/Handlers/MessageHandler.h b/source/tools/atlas/GameInterface/Handlers/MessageHandler.h index 415b6ebbd9..385cf10873 100644 --- a/source/tools/atlas/GameInterface/Handlers/MessageHandler.h +++ b/source/tools/atlas/GameInterface/Handlers/MessageHandler.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -36,7 +36,7 @@ extern msgHandlers& GetMsgHandlers(); ENSURE(msg->GetType() == IMessage::expectedtype); \ f##t (static_cast(msg)); \ } \ - void f##t(prefix##t* msg) + void f##t([[maybe_unused]] prefix##t* msg) #define MESSAGEHANDLER(t) THINGHANDLER(m, Message, t) #define QUERYHANDLER(t) THINGHANDLER(q, Query, t) diff --git a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp index c9539cf8a9..10f7117390 100644 --- a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -55,13 +55,10 @@ MESSAGEHANDLER(Screenshot) QUERYHANDLER(Ping) { - UNUSED2(msg); } MESSAGEHANDLER(SimStopMusic) { - UNUSED2(msg); - CmpPtr cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); if (cmpSoundManager) cmpSoundManager->StopMusic(); diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index 7f63f74099..b30235497c 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -412,8 +412,6 @@ QUERYHANDLER(GetCurrentSelection) MESSAGEHANDLER(ObjectPreviewToEntity) { - UNUSED2(msg); - if (g_PreviewEntitiesID.size() == 0) return; @@ -713,8 +711,6 @@ QUERYHANDLER(PickSimilarObjects) MESSAGEHANDLER(ResetSelectionColor) { - UNUSED2(msg); - for (entity_id_t ent : g_Selection) { CmpPtr cmpVisual(*g_Game->GetSimulation2(), ent);