From 08d8f0f61cf910ba53eee7bb568f72a43e484819 Mon Sep 17 00:00:00 2001 From: phosit Date: Wed, 21 May 2025 12:54:45 +0200 Subject: [PATCH] Remove UNUSED2 The remaining uses can be changed to `std::ignore`. Fix #7760 --- source/lib/code_annotation.h | 15 --------------- source/lib/file/io/io.h | 4 +++- source/lib/sysdep/os/win/tests/test_wdbg_sym.h | 14 +++++++------- source/lib/sysdep/os/win/wnuma.cpp | 15 ++++++++------- source/lib/sysdep/os/win/wversion.cpp | 4 +++- source/lib/sysdep/smbios.cpp | 3 +-- 6 files changed, 22 insertions(+), 33 deletions(-) diff --git a/source/lib/code_annotation.h b/source/lib/code_annotation.h index 5e55570375..ee278e2906 100644 --- a/source/lib/code_annotation.h +++ b/source/lib/code_annotation.h @@ -33,21 +33,6 @@ #include -/** - * mark a function local variable or parameter as unused and avoid - * the corresponding compiler warning. - * note that UNUSED is not applicable to variable definitions that - * involve initialization, nor is it sufficient in cases where - * an argument is unused only in certain situations. - * example: void f(int x) { ASSERT(x == 0); UNUSED2(x); } - * this asserts in debug builds and avoids warnings in release. - **/ -#if HAVE_C99 && GCC_VERSION // _Pragma from C99, unused from GCC -# define UNUSED2(param) _Pragma("unused " #param) -#else -# define UNUSED2(param) ((void)(param)) -#endif - /** * indicate a function will not throw any synchronous exceptions, * thus hopefully generating smaller and more efficient code. diff --git a/source/lib/file/io/io.h b/source/lib/file/io/io.h index 03542cd673..fdb98be213 100644 --- a/source/lib/file/io/io.h +++ b/source/lib/file/io/io.h @@ -49,6 +49,8 @@ #include #include +#include + namespace ERR { const Status IO = -110301; @@ -327,7 +329,7 @@ static inline Status Store(const OsPath& pathname, const void* data, size_t size io::Operation op(file, (void*)data, size); #if OS_WIN - UNUSED2(waio_Preallocate(op.m_FileDescriptor, (off_t)size)); + std::ignore = waio_Preallocate(op.m_FileDescriptor, (off_t)size); #endif RETURN_STATUS_IF_ERR(io::Run(op, p, completedHook, issueHook)); 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 9c1d09948e..733abe5afe 100644 --- a/source/lib/sysdep/os/win/tests/test_wdbg_sym.h +++ b/source/lib/sysdep/os/win/tests/test_wdbg_sym.h @@ -27,12 +27,6 @@ #include "lib/self_test.h" -#include -#include -#include -#include -#include - #include "lib/bits.h" #include "lib/code_annotation.h" #include "lib/sysdep/os/win/win.h" // HWND @@ -40,6 +34,12 @@ #include "lib/sysdep/os/win/wdbg_sym.h" #include "lib/external_libraries/dbghelp.h" +#include +#include +#include +#include +#include +#include static void* callers[100]; static size_t numCallers; @@ -60,7 +60,7 @@ static Status OnFrame(const _tagSTACKFRAME64* frame, uintptr_t /*cbData*/) __declspec(noinline) static void Func1() { CONTEXT context; - UNUSED2(debug_CaptureContext(&context)); + std::ignore = debug_CaptureContext(&context); wdbg_sym_WalkStack(OnFrame, 0, context); } diff --git a/source/lib/sysdep/os/win/wnuma.cpp b/source/lib/sysdep/os/win/wnuma.cpp index 7a4697d19a..cf1ff808eb 100644 --- a/source/lib/sysdep/os/win/wnuma.cpp +++ b/source/lib/sysdep/os/win/wnuma.cpp @@ -37,6 +37,7 @@ #include #include +#include #if ARCH_X86_X64 #include "lib/sysdep/arch/x86_x64/apic.h" // ProcessorFromApicId @@ -301,13 +302,13 @@ static Status InitTopology() size_t numa_NumNodes() { - UNUSED2(ModuleInit(&initState, InitTopology)); + std::ignore = ModuleInit(&initState, InitTopology); return numNodes; } size_t numa_NodeFromProcessor(size_t processor) { - UNUSED2(ModuleInit(&initState, InitTopology)); + std::ignore = ModuleInit(&initState, InitTopology); ENSURE(processor < os_cpu_NumProcessors()); Node* node = FindNodeWithProcessor(processor); ENSURE(node); @@ -316,14 +317,14 @@ size_t numa_NodeFromProcessor(size_t processor) uintptr_t numa_ProcessorMaskFromNode(size_t node) { - UNUSED2(ModuleInit(&initState, InitTopology)); + std::ignore = ModuleInit(&initState, InitTopology); ENSURE(node < numNodes); return nodes[node].processorMask; } static UCHAR NodeNumberFromNode(size_t node) { - UNUSED2(ModuleInit(&initState, InitTopology)); + std::ignore = ModuleInit(&initState, InitTopology); ENSURE(node < numa_NumNodes()); return nodes[node].nodeNumber; } @@ -401,7 +402,7 @@ static double MeasureRelativeDistance() maxTime = std::max(maxTime, elapsedTime); } - UNUSED2(os_cpu_SetThreadAffinityMask(previousProcessorMask)); + std::ignore = os_cpu_SetThreadAffinityMask(previousProcessorMask); vm::Free(mem, size); @@ -434,7 +435,7 @@ static Status InitRelativeDistance() double numa_Factor() { static ModuleInitState _initState{ 0 }; - UNUSED2(ModuleInit(&_initState, InitRelativeDistance)); + std::ignore = ModuleInit(&_initState, InitRelativeDistance); return relativeDistance; } @@ -464,7 +465,7 @@ static Status InitMemoryInterleaved() bool numa_IsMemoryInterleaved() { static ModuleInitState _initState{ 0 }; - UNUSED2(ModuleInit(&_initState, InitMemoryInterleaved)); + std::ignore = ModuleInit(&_initState, InitMemoryInterleaved); return isMemoryInterleaved; } diff --git a/source/lib/sysdep/os/win/wversion.cpp b/source/lib/sysdep/os/win/wversion.cpp index 158b9d5b7b..5c3ea87f77 100644 --- a/source/lib/sysdep/os/win/wversion.cpp +++ b/source/lib/sysdep/os/win/wversion.cpp @@ -26,6 +26,7 @@ #include "lib/sysdep/os/win/win.h" #include +#include const char* wversion_Family() { @@ -37,7 +38,8 @@ const char* wversion_Family() { wchar_t windowsVersionString[32]; DWORD size = sizeof(windowsVersionString); - UNUSED2(RegQueryValueExW(hKey, L"CurrentVersion", 0, 0, reinterpret_cast(windowsVersionString), &size)); + std::ignore = RegQueryValueExW(hKey, L"CurrentVersion", 0, 0, + reinterpret_cast(windowsVersionString), &size); unsigned major = 0, minor = 0; swscanf_s(windowsVersionString, L"%u.%u", &major, &minor); diff --git a/source/lib/sysdep/smbios.cpp b/source/lib/sysdep/smbios.cpp index 0a83ba6a74..0a27dd4ceb 100644 --- a/source/lib/sysdep/smbios.cpp +++ b/source/lib/sysdep/smbios.cpp @@ -703,10 +703,9 @@ void FieldStringizer::operator()(size_t flags, const char*& value, const Structures* GetStructures() { static ModuleInitState initState{ 0 }; - Status ret = ModuleInit(&initState, InitStructures); + std::ignore = ModuleInit(&initState, InitStructures); // (callers have to check if member pointers are nonzero anyway, so // we always return a valid pointer to simplify most use cases.) - UNUSED2(ret); return &g_Structures; }