Created on 2022-10-20.00:00:00 last changed 16 months ago
Proposed resolution (approved by CWG 2022-10-21):
Change in 9.1 [dcl.pre] paragraph 6 specifies:
A simple-declaration with an identifier-list is called a structured binding declaration (9.6 [dcl.struct.bind]).If the decl-specifier-seq contains any decl-specifier other than static, thread_local, auto (9.2.9.7 [dcl.spec.auto]), or cv-qualifiers, the program is ill-formed.Each decl-specifier in the decl-specifier-seq shall be static, thread_local, auto (9.2.9.7 [dcl.spec.auto]), or a cv-qualifier. [ Example:template<class T> concept C = true; C auto [x, y] = std::pair{1, 2}; // error: constrained placeholder-type-specifier not permitted for structured bindings
-- end example ]
[Accepted as a DR at the November, 2022 meeting.]
Consider:
template<class T> concept C = true;
C auto [x, y] = std::pair{1, 2}; // ok?
Subclause 9.1 [dcl.pre] paragraph 6 specifies:
A simple-declaration with an identifier-list is called a structured binding declaration (9.6 [dcl.struct.bind]). If the decl-specifier-seq contains any decl-specifier other than static, thread_local, auto (9.2.9.7 [dcl.spec.auto]), or cv-qualifier s, the program is ill-formed.
Use of the word "contains" leads to an interpretation that any placeholder-type-specifier (9.2.9.7.1 [dcl.spec.auto.general]), possibly including a type-constraint, is valid here, since a placeholder-type-specifier is a decl-specifier and "contains" auto.
However, paper P1141R2 (Yet another approach for constrained declarations), applied in November 2018, expressly excludes structured bindings from constrained auto:
Structured bindings do deduce auto in some cases; however, the auto is deduced from the whole (and not from the individual components). It is somewhat doubtful that applying the constraint to the whole, as opposed to (for example) applying separately to each component, is the correct semantic. Therefore, we propose to defer enabling the application of constraints to structured bindings to separate papers.
Notwithstanding, clang, gcc, and MSVC accept the example.
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-07-16 13:00:43 | admin | set | status: open -> c++23 |
2023-07-16 13:00:43 | admin | set | status: drwp -> open |
2023-02-18 18:43:04 | admin | set | status: dr -> drwp |
2022-11-25 05:14:04 | admin | set | status: ready -> dr |
2022-10-21 20:41:10 | admin | set | messages: + msg6953 |
2022-10-21 20:41:10 | admin | set | status: open -> ready |
2022-10-20 00:00:00 | admin | create |