Add NXT_UNUSED to silence unused warnings

This commit is contained in:
Corentin Wallez
2018-06-12 10:28:52 -04:00
committed by Corentin Wallez
parent 5ab96e0d40
commit 82565b340f
5 changed files with 10 additions and 6 deletions

View File

@@ -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

View File

@@ -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 @@ extern void __cdecl __debugbreak(void);
# 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

View File

@@ -51,7 +51,7 @@ TEST_F(BitSetIteratorTest, EmptySet) {
// 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);

View File

@@ -178,7 +178,7 @@ TEST(ErrorTests, TRY_RESULT_Error) {
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 @@ TEST(ErrorTests, TRY_RESULT_ConversionToError) {
auto Try = [ReturnError]() -> MaybeError {
int* result = nullptr;
NXT_TRY_ASSIGN(result, ReturnError());
(void) result;
NXT_UNUSED(result);
return {};
};

View File

@@ -27,7 +27,7 @@ TEST(SerialQueue, BasicTest) {
// 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 @@ TEST(SerialQueue, BasicTest) {
ASSERT_TRUE(queue.Empty());
for (int value : queue.IterateAll()) {
(void) value;
NXT_UNUSED(value);
ASSERT_TRUE(false);
}
}