From 3bc3d755fba3c1c8e62088d9d155bd170e0efdd8 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Tue, 2 Jul 2024 20:33:40 +0200 Subject: [PATCH] P0963R3 Structured binding declaration as a condition --- source/declarations.tex | 21 ++++++++++++++++----- source/statements.tex | 34 ++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/source/declarations.tex b/source/declarations.tex index 1602d6ab3e..987905fa4c 100644 --- a/source/declarations.tex +++ b/source/declarations.tex @@ -208,7 +208,8 @@ \end{example} \pnum -A \grammarterm{simple-declaration} with a \grammarterm{structured-binding-declaration} is called +A \grammarterm{simple-declaration} or a \grammarterm{condition} +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 @@ -227,9 +228,13 @@ of the form ``\tcode{=} \grammarterm{assignment-expression}'', of the form ``\tcode{\{} \grammarterm{assignment-expression} \tcode{\}}'', or -of the form ``\tcode{(} \grammarterm{assignment-expression} \tcode{)}'', -where the -\grammarterm{assignment-expression} is of array or non-union class type. +of the form ``\tcode{(} \grammarterm{assignment-expression} \tcode{)}''. +If the \grammarterm{structured-binding-declaration} appears as +a \grammarterm{condition}, +the \grammarterm{assignment-expression} shall be of non-union class type. +Otherwise, +the \grammarterm{assignment-expression} shall be of +array or non-union class type. \pnum If the \grammarterm{decl-specifier-seq} contains the \keyword{typedef} @@ -7051,6 +7056,10 @@ \tcode{E} is never a reference type\iref{expr.prop}. \end{note} +\pnum +If a structured binding declaration appears as a \grammarterm{condition}, +the decision variable\iref{stmt.pre} of the condition is \exposid{e}. + \pnum If the \grammarterm{initializer} refers to one of the names introduced by the structured binding declaration, @@ -7114,7 +7123,9 @@ Each $\tcode{v}_i$ is the name of an lvalue of type $\tcode{T}_i$ that refers to the object bound to $\tcode{r}_i$; the referenced type is $\tcode{T}_i$. -The initialization of \exposid{e} is +The initialization of \exposid{e} and +any conversion of \exposid{e} considered as a decision variable\iref{stmt.pre} +is sequenced before the initialization of any $\tcode{r}_i$. The initialization of each $\tcode{r}_i$ is sequenced before the initialization of any $\tcode{r}_j$ where $i < j$. diff --git a/source/statements.tex b/source/statements.tex index 0d8ae2a439..94f8a6b2e7 100644 --- a/source/statements.tex +++ b/source/statements.tex @@ -33,7 +33,8 @@ \begin{bnf} \nontermdef{condition}\br expression\br - \opt{attribute-specifier-seq} decl-specifier-seq declarator brace-or-equal-initializer + \opt{attribute-specifier-seq} decl-specifier-seq declarator brace-or-equal-initializer\br + structured-binding-declaration initializer \end{bnf} The optional \grammarterm{attribute-specifier-seq} appertains to the respective statement. @@ -86,8 +87,12 @@ The rules for \grammarterm{condition}{s} apply both to \grammarterm{selection-statement}{s}\iref{stmt.select} and to the \keyword{for} and \keyword{while} statements\iref{stmt.iter}. -A \grammarterm{condition} that is not an \grammarterm{expression} is a -declaration\iref{dcl.dcl}. +If a \grammarterm{structured-binding-declaration} +appears in a \grammarterm{condition}, +the \grammarterm{condition} is a structured binding declaration\iref{dcl.pre}. +A \grammarterm{condition} that is +neither an \grammarterm{expression} nor a structured binding declaration +is a declaration\iref{dcl.dcl}. The \grammarterm{declarator} shall not specify a function or an array. The \grammarterm{decl-specifier-seq} shall not define a class or enumeration. If the \keyword{auto} \grammarterm{type-specifier} appears in @@ -95,9 +100,16 @@ the type of the identifier being declared is deduced from the initializer as described in~\ref{dcl.spec.auto}. \pnum -The value of a \grammarterm{condition} that is an initialized declaration +The \defnadj{decision}{variable} of a \grammarterm{condition} +that is neither an \grammarterm{expression} nor a structured binding declaration +is the declared variable. +The decision variable of a \grammarterm{condition} +that is a structured binding declaration is specified in \ref{dcl.struct.bind}. + +\pnum +The value of a \grammarterm{condition} that is not an \grammarterm{expression} in a statement other than a \keyword{switch} statement is the value of the -declared variable +decision variable contextually converted to \tcode{bool}\iref{conv}. If that conversion is ill-formed, the program is ill-formed. @@ -116,7 +128,10 @@ it is interpreted as the latter. \pnum -In the \grammarterm{decl-specifier-seq} of a \grammarterm{condition}, each +In the \grammarterm{decl-specifier-seq} of a \grammarterm{condition}, +including that of any \grammarterm{structured-binding-declaration} of +the \grammarterm{condition}, +each \grammarterm{decl-specifier} shall be either a \grammarterm{type-specifier} or \keyword{constexpr}. @@ -408,10 +423,9 @@ several statements depending on the value of a condition. \pnum -The value of a \grammarterm{condition} -that is an initialized declaration -is the value of the declared variable, -or the value of the \grammarterm{expression} otherwise. +If the \grammarterm{condition} is an \grammarterm{expression}, +the value of the condition is the value of the \grammarterm{expression}; +otherwise, it is the value of the decision variable. The value of the condition shall be of integral type, enumeration type, or class type. If of class type, the condition is contextually implicitly converted\iref{conv} to