From 41efe541c7c161823b05c0207c4d4d34d6f1c1bd Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Sat, 23 Mar 2024 11:20:15 +0100 Subject: [PATCH] P0609R3 Attributes for Structured Bindings --- source/declarations.tex | 32 ++++++++++++++++++++++++++------ source/preprocessor.tex | 2 +- source/statements.tex | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/source/declarations.tex b/source/declarations.tex index 564ddd66f1..d00d2d6f8f 100644 --- a/source/declarations.tex +++ b/source/declarations.tex @@ -67,11 +67,27 @@ \keyword{using} identifier \opt{attribute-specifier-seq} \terminal{=} defining-type-id \terminal{;} \end{bnf} +\begin{bnf} +\nontermdef{attributed-identifier}\br + identifier \opt{attribute-specifier-seq} +\end{bnf} + +\begin{bnf} +\nontermdef{attributed-identifier-list}\br + attributed-identifier\br + attributed-identifier-list \terminal{,} attributed-identifier +\end{bnf} + +\begin{bnf} +\nontermdef{structured-binding-declaration}\br + \opt{attribute-specifier-seq} decl-specifier-seq \opt{ref-qualifier} \terminal{[} attributed-identifier-list \terminal{]} +\end{bnf} + \begin{bnf} \nontermdef{simple-declaration}\br decl-specifier-seq \opt{init-declarator-list} \terminal{;}\br attribute-specifier-seq decl-specifier-seq init-declarator-list \terminal{;}\br - \opt{attribute-specifier-seq} decl-specifier-seq \opt{ref-qualifier} \terminal{[} identifier-list \terminal{]} initializer \terminal{;} + structured-binding-declaration initializer \terminal{;} \end{bnf} \begin{bnf} @@ -186,7 +202,7 @@ \end{example} \pnum -A \grammarterm{simple-declaration} with an \grammarterm{identifier-list} is called +A \grammarterm{simple-declaration} with a \grammarterm{structured-binding-declaration} is called a \defn{structured binding declaration}\iref{dcl.struct.bind}. Each \grammarterm{decl-specifier} in the \grammarterm{decl-specifier-seq} shall be @@ -6968,8 +6984,11 @@ A structured binding declaration introduces the \grammarterm{identifier}{s} $\tcode{v}_0$, $\tcode{v}_1$, $\tcode{v}_2, \dotsc$ of the -\grammarterm{identifier-list} as names +\grammarterm{attributed-identifier-list} as names of \defn{structured binding}{s}. +The optional \grammarterm{attribute-specifier-seq} of +an \grammarterm{attributed-identifier} +appertains to the structured binding so introduced. Let \cv{} denote the \grammarterm{cv-qualifier}{s} in the \grammarterm{decl-specifier-seq} and \placeholder{S} consist of the \grammarterm{storage-class-specifier}{s} of @@ -7008,7 +7027,7 @@ \pnum If \tcode{E} is an array type with element type \tcode{T}, the number -of elements in the \grammarterm{identifier-list} shall be equal to the +of elements in the \grammarterm{attributed-identifier-list} shall be equal to the number of elements of \tcode{E}. Each $\tcode{v}_i$ is the name of an lvalue that refers to the element $i$ of the array and whose type is \tcode{T}; the referenced type is \tcode{T}. @@ -7031,7 +7050,7 @@ shall be a well-formed integral constant expression and the number of elements in -the \grammarterm{identifier-list} shall be equal to the value of that +the \grammarterm{attributed-identifier-list} shall be equal to the value of that expression. Let \tcode{i} be an index prvalue of type \tcode{std::size_t} corresponding to $\tcode{v}_i$. @@ -7073,7 +7092,7 @@ well-formed when named as \tcode{\exposidnc{e}.\placeholder{name}} in the context of the structured binding, \tcode{E} shall not have an anonymous union member, and -the number of elements in the \grammarterm{identifier-list} shall be +the number of elements in the \grammarterm{attributed-identifier-list} shall be equal to the number of non-static data members of \tcode{E}. Designating the non-static data members of \tcode{E} as $\tcode{m}_0$, $\tcode{m}_1$, $\tcode{m}_2, \dotsc$ @@ -9246,6 +9265,7 @@ The attribute may be applied to the declaration of a class, \grammarterm{typedef-name}, variable (including a structured binding declaration), +structured binding, non-static data member, function, enumeration, or diff --git a/source/preprocessor.tex b/source/preprocessor.tex index 827497f2e3..c528aa576b 100644 --- a/source/preprocessor.tex +++ b/source/preprocessor.tex @@ -1868,7 +1868,7 @@ \defnxname{cpp_sized_deallocation} & \tcode{201309L} \\ \rowsep \defnxname{cpp_static_assert} & \tcode{202306L} \\ \rowsep \defnxname{cpp_static_call_operator} & \tcode{202207L} \\ \rowsep -\defnxname{cpp_structured_bindings} & \tcode{201606L} \\ \rowsep +\defnxname{cpp_structured_bindings} & \tcode{202403L} \\ \rowsep \defnxname{cpp_template_template_args} & \tcode{201611L} \\ \rowsep \defnxname{cpp_threadsafe_static_init} & \tcode{200806L} \\ \rowsep \defnxname{cpp_unicode_characters} & \tcode{200704L} \\ \rowsep diff --git a/source/statements.tex b/source/statements.tex index a6693a7afe..c3b943186d 100644 --- a/source/statements.tex +++ b/source/statements.tex @@ -509,7 +509,7 @@ \begin{bnf} \nontermdef{for-range-declaration}\br \opt{attribute-specifier-seq} decl-specifier-seq declarator\br - \opt{attribute-specifier-seq} decl-specifier-seq \opt{ref-qualifier} \terminal{[} identifier-list \terminal{]} + structured-binding-declaration \end{bnf} \begin{bnf}