Difference between revisions of "cpp/language/attributes/maybe unused"
From cppreference.com
< cpp | language | attributes
m (T. Canens moved page cpp/attribute/maybe unused to cpp/language/attributes/maybe unused without leaving a redirect: Text replace - "cpp/attribute" to "cpp/language/attributes") |
m (Text replace - "cpp/attribute" to "cpp/language/attributes") |
||
Line 1: | Line 1: | ||
− | {{cpp/ | + | {{cpp/language/attributes/title|maybe_unused|notes={{mark since c++17}}}} |
− | {{cpp/ | + | {{cpp/language/attributes/navbar}} |
If the compiler issues warnings on unused entities, that warning is suppressed for any entity declared maybe_unused. | If the compiler issues warnings on unused entities, that warning is suppressed for any entity declared maybe_unused. |
Revision as of 07:46, 24 June 2018
If the compiler issues warnings on unused entities, that warning is suppressed for any entity declared maybe_unused.
Syntax
class-key [[maybe_unused]] class-name ;
|
(1) | ||||||||
class-key [[maybe_unused]] class-name final(optional) base-clause(optional) { member-specification }
|
(2) | ||||||||
using identifier [[maybe_unused]] = defining-type-id ;
|
(3) | ||||||||
[[maybe_unused]] declaration
|
(4) | ||||||||
declarator-id [[maybe_unused]]
|
(5) | ||||||||
enum-key [[maybe_unused]] enumeration-name enum-base(optional) ;
|
(6) | ||||||||
enum-key [[maybe_unused]] enumeration-name enum-base(optional) { enumerator-list }
|
(7) | ||||||||
enumerator [[maybe_unused]]
|
(8) | ||||||||
Explanation
Appears in the declaration of a class, a typedef, a variable, a nonstatic data member, a function, an enumeration, or an enumerator.
If the compiler issues warnings on unused entities, that warning is suppressed for any entity declared maybe_unused.
Example
Run this code
[[maybe_unused]] void f([[maybe_unused]] bool thing1, [[maybe_unused]] bool thing2) { [[maybe_unused]] bool b = thing1 && thing2; assert(b); // in release mode, assert is compiled out, and b is unused // no warning because it is declared [[maybe_unused]] } // parameters thing1 and thing2 are not used, no warning