Add NXT_UNUSED to silence unused warnings
diff --git a/src/common/Assert.h b/src/common/Assert.h
index 71d730e..3ba7fa2 100644
--- a/src/common/Assert.h
+++ b/src/common/Assert.h
@@ -55,7 +55,7 @@
# else
# define NXT_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
do { \
- (void)sizeof(condition); \
+ NXT_UNUSED(sizeof(condition)); \
} while (NXT_ASSERT_LOOP_CONDITION)
# endif
#endif
diff --git a/src/common/Compiler.h b/src/common/Compiler.h
index 608ad77..36ddd39 100644
--- a/src/common/Compiler.h
+++ b/src/common/Compiler.h
@@ -22,6 +22,7 @@
// - NXT_NO_DISCARD: An attribute that is C++17 [[nodiscard]] where available
// - NXT_(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.
+// - NXT_UNUSED(EXPR): Prevents unused variable/expression warnings on EXPR.
// Clang and GCC
#if defined(__GNUC__)
@@ -72,6 +73,9 @@
# error "Unsupported compiler"
#endif
+// It seems that (void) EXPR works on all compilers to silence the unused variable warning.
+#define NXT_UNUSED(EXPR) (void)EXPR
+
// Add noop replacements for macros for features that aren't supported by the compiler.
#if !defined(NXT_LIKELY)
# define NXT_LIKELY(X) X
diff --git a/src/tests/unittests/BitSetIteratorTests.cpp b/src/tests/unittests/BitSetIteratorTests.cpp
index 4ea7b68..50198a9 100644
--- a/src/tests/unittests/BitSetIteratorTests.cpp
+++ b/src/tests/unittests/BitSetIteratorTests.cpp
@@ -51,7 +51,7 @@
// causing an unreachable code warning in MSVS
bool sawBit = false;
for (unsigned long bit : IterateBitSet(mStateBits)) {
- (void) bit;
+ NXT_UNUSED(bit);
sawBit = true;
}
EXPECT_FALSE(sawBit);
diff --git a/src/tests/unittests/ErrorTests.cpp b/src/tests/unittests/ErrorTests.cpp
index 7320ad9..26af084 100644
--- a/src/tests/unittests/ErrorTests.cpp
+++ b/src/tests/unittests/ErrorTests.cpp
@@ -178,7 +178,7 @@
auto Try = [ReturnError]() -> ResultOrError<int*> {
int* result = nullptr;
NXT_TRY_ASSIGN(result, ReturnError());
- (void) result;
+ NXT_UNUSED(result);
// NXT_TRY should return before this point
EXPECT_FALSE(true);
@@ -233,7 +233,7 @@
auto Try = [ReturnError]() -> MaybeError {
int* result = nullptr;
NXT_TRY_ASSIGN(result, ReturnError());
- (void) result;
+ NXT_UNUSED(result);
return {};
};
diff --git a/src/tests/unittests/SerialQueueTests.cpp b/src/tests/unittests/SerialQueueTests.cpp
index 7f0ca3d..126b3a4 100644
--- a/src/tests/unittests/SerialQueueTests.cpp
+++ b/src/tests/unittests/SerialQueueTests.cpp
@@ -27,7 +27,7 @@
// Iterating on empty queue 1) works 2) doesn't produce any values
for (int value : queue.IterateAll()) {
- (void) value;
+ NXT_UNUSED(value);
ASSERT_TRUE(false);
}
@@ -50,7 +50,7 @@
ASSERT_TRUE(queue.Empty());
for (int value : queue.IterateAll()) {
- (void) value;
+ NXT_UNUSED(value);
ASSERT_TRUE(false);
}
}