[dcl.attr.unused]

# 9 Declarations [[dcl]](./#dcl)

## 9.13 Attributes [[dcl.attr]](dcl.attr#unused)

### 9.13.8 Maybe unused attribute [dcl.attr.unused]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9947)

The [*attribute-token*](dcl.attr.grammar#nt:attribute-token "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") maybe_unused indicates that a name, label, or entity is possibly intentionally unused[.](#1.sentence-1)

No [*attribute-argument-clause*](dcl.attr.grammar#nt:attribute-argument-clause "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") shall be present[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9952)

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]](dcl.contract.res "9.4.2 Referring to the result object")),
non-static data member,
function,
enumeration, or
enumerator, or
to an [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") label ([[stmt.label]](stmt.label "8.2 Label"))[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9964)

A name or entity declared without the maybe_unused attribute
can later be redeclared with the attribute
and vice versa[.](#3.sentence-1)

An entity is considered marked
after the first declaration that marks it[.](#3.sentence-2)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9971)

*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[.](#4.sentence-1)

For a structured binding declaration not marked maybe_unused,
implementations should not emit such a warning unless
all of its structured bindings are unused[.](#4.sentence-2)

For a label to which maybe_unused is applied,
implementations should not emit a warning that the label is used or unused[.](#4.sentence-3)

The value of
a [*has-attribute-expression*](cpp.cond#nt:has-attribute-expression "15.2 Conditional inclusion [cpp.cond]") for the maybe_unused attribute
should be 0 if the attribute does not cause suppression of such warnings[.](#4.sentence-4)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9987)

[*Example [1](#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;#endif[[maybe_unused]] x:}

Implementations should not warn that b or x is unused,
whether or not NDEBUG is defined[.](#5.sentence-1)

â *end example*]
