Files
2025-10-25 03:02:53 +03:00

2.9 KiB

[dcl.attr.unused]

9 Declarations [dcl]

9.13 Attributes [dcl.attr]

9.13.8 Maybe unused attribute [dcl.attr.unused]

1

#

The attribute-token maybe_unused indicates that a name, label, or entity is possibly intentionally unused.

No attribute-argument-clause shall be present.

2

#

The attribute may be applied to the declaration of a class, type alias, variable (including a structured binding declaration), structured binding, result binding ([dcl.contract.res]), non-static data member, function, enumeration, or enumerator, or to an identifier label ([stmt.label]).

3

#

A name or entity declared without the maybe_unused attribute can later be redeclared with the attribute and vice versa.

An entity is considered marked after the first declaration that marks it.

4

#

Recommended practice: For an entity marked maybe_unused, implementations should not emit a warning that the entity or its structured bindings (if any) are used or unused.

For a structured binding declaration not marked maybe_unused, implementations should not emit such a warning unless all of its structured bindings are unused.

For a label to which maybe_unused is applied, implementations should not emit a warning that the label is used or unused.

The value of a has-attribute-expression for the maybe_unused attribute should be 0 if the attribute does not cause suppression of such warnings.

5

#

[Example 1: maybe_unused void f(maybe_unused bool thing1, maybe_unused bool thing2) {maybe_unused bool b = thing1 && thing2; assert(b);#ifdef NDEBUG goto x;#endifmaybe_unused x:}

Implementations should not warn that b or x is unused, whether or not NDEBUG is defined.

— end example]