Namespaces
Variants
Views
Actions

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/attribute/title|maybe_unused|notes={{mark since c++17}}}}
+
{{cpp/language/attributes/title|maybe_unused|notes={{mark since c++17}}}}
{{cpp/attribute/navbar}}
+
{{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

 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++17*)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static

Special member functions
Templates
Miscellaneous
 
 
Attributes
(C++23)
(C++14)
(C++20)
maybe_unused
(C++17)
(C++17)
(C++11)
(C++20)
 

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 non­static 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

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