Suppresses warnings on unused entities.
[[ maybe_unused ]] [[ __maybe_unused__ ]] |
This attribute can appear in the declaration of the following entities:
struct [[maybe_unused]] S;
, [[maybe_unused]] typedef S* PS;
, [[maybe_unused]] int x;
, union U { [[maybe_unused]] int n; };
, [[maybe_unused]] void f(void);
, enum [[maybe_unused]] E {};
, enum { A [[maybe_unused]], B [[maybe_unused]] = 42 };
. If the compiler issues warnings on unused entities, that warning is suppressed for any entity declared maybe_unused
.
#include <assert.h> [[maybe_unused]] void f([[maybe_unused]] _Bool cond1, [[maybe_unused]] _Bool cond2) { [[maybe_unused]] _Bool b = cond1 && cond2; assert(b); // in release mode, assert is compiled out, and b is unused // no warning because it is declared [[maybe_unused]] } // parameters cond1 and cond2 are not used, no warning int main(void) { f(1, 1); }
C++ documentation for maybe_unused |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/c/language/attributes/maybe_unused