This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


2360. [[maybe_unused]] and structured bindings

Section: 9.12.9  [dcl.attr.unused]     Status: CD5     Submitter: Michael Wong     Date: 2017-10-19

[Accepted as a DR at the February, 2019 meeting.]

According to9.12.9 [dcl.attr.unused] paragraph 2,

The attribute may be applied to the declaration of a class, a typedef-name, a variable, a non-static data member, a function, an enumeration, or an enumerator.

This does not include structured bindings, although there seems to be no good reason to prohibit uses like

  [[maybe_unused]] auto [a, b] = std::make_pair(42, 0.23);

Notes from the October, 2018 teleconference:

CWG agreed that such an annotation should be permitted and apply to the underlying variable; i.e., a compiler might warn in the absence of such an attribute if none of the structured bindings were used, and the presence of the attribute would silence such warnings.

Proposed resolution (November, 2018):

Change 9.12.9 [dcl.attr.unused] paragraphs 2 and 3 as follows:

The attribute may be applied to the declaration of a class, a typedef-name, a variable (including a structured binding declaration), a non-static data member, a function, an enumeration, or an enumerator.

[Note: For an entity marked maybe_unused, implementations should not emit a warning that the entity is or its structured bindings (if any) are used or unused. , or that the entity is used despite the presence of the attribute. —end note] For a structured binding declaration not marked maybe_unused, implementations should not emit such a warning unless all of its structured bindings are unused.