Skip to content

Commit 882a22c

Browse files
committed
P0963R3 Structured binding declaration as a condition
1 parent 6d67d20 commit 882a22c

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

source/declarations.tex

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@
208208
\end{example}
209209

210210
\pnum
211-
A \grammarterm{simple-declaration} with a \grammarterm{structured-binding-declaration} is called
211+
A \grammarterm{simple-declaration} or a \grammarterm{condition}
212+
with a \grammarterm{structured-binding-declaration} is called
212213
a \defn{structured binding declaration}\iref{dcl.struct.bind}.
213214
Each \grammarterm{decl-specifier} in the \grammarterm{decl-specifier-seq}
214215
shall be
@@ -227,9 +228,13 @@
227228
of the form ``\tcode{=} \grammarterm{assignment-expression}'',
228229
of the form ``\tcode{\{} \grammarterm{assignment-expression} \tcode{\}}'',
229230
or
230-
of the form ``\tcode{(} \grammarterm{assignment-expression} \tcode{)}'',
231-
where the
232-
\grammarterm{assignment-expression} is of array or non-union class type.
231+
of the form ``\tcode{(} \grammarterm{assignment-expression} \tcode{)}''.
232+
If the \grammarterm{structured-binding-declaration} appears as
233+
a \grammarterm{condition},
234+
the \grammarterm{assignment-expression} shall be of non-union class type.
235+
Otherwise,
236+
the \grammarterm{assignment-expression} shall be of
237+
array or non-union class type.
233238

234239
\pnum
235240
If the \grammarterm{decl-specifier-seq} contains the \keyword{typedef}
@@ -7042,6 +7047,10 @@
70427047
\tcode{E} is never a reference type\iref{expr.prop}.
70437048
\end{note}
70447049

7050+
\pnum
7051+
If a structured binding declaration appears as a \grammarterm{condition},
7052+
the decision variable\iref{stmt.pre} of the condition is \tcode{e}.
7053+
70457054
\pnum
70467055
If the \grammarterm{initializer} refers to
70477056
one of the names introduced by the structured binding declaration,
@@ -7105,6 +7114,11 @@
71057114
Each $\tcode{v}_i$ is the name of an lvalue of type $\tcode{T}_i$
71067115
that refers to the object bound to $\tcode{r}_i$;
71077116
the referenced type is $\tcode{T}_i$.
7117+
The initialization of \tcode{e} and
7118+
any conversion of \tcode{e} considered as a decision variable\iref{stmt.pre}
7119+
is sequenced before the initialization of any $\tcode{r}_i$.
7120+
The initialization of $\tcode{r}_i$ is sequenced before
7121+
the initialization of $\tcode{r}_j$ if $i < j$.
71087122

71097123
\pnum
71107124
Otherwise,

source/statements.tex

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
\nontermdef{condition}\br
3535
expression\br
3636
\opt{attribute-specifier-seq} decl-specifier-seq declarator brace-or-equal-initializer
37+
structured-binding-declaration initializer
3738
\end{bnf}
3839

3940
The optional \grammarterm{attribute-specifier-seq} appertains to the respective statement.
@@ -86,18 +87,29 @@
8687
The rules for \grammarterm{condition}{s} apply both
8788
to \grammarterm{selection-statement}{s}\iref{stmt.select} and
8889
to the \keyword{for} and \keyword{while} statements\iref{stmt.iter}.
89-
A \grammarterm{condition} that is not an \grammarterm{expression} is a
90-
declaration\iref{dcl.dcl}.
90+
If a \grammarterm{structured-binding-declaration}
91+
appears in a \grammarterm{condition},
92+
the \grammarterm{condition} is a structured binding declaration\iref{dcl.pre}.
93+
A \grammarterm{condition} that is
94+
neither an \grammarterm{expression} nor a structured binding declaration
95+
is a declaration\iref{dcl.dcl}.
9196
The \grammarterm{declarator} shall not
9297
specify a function or an array. The \grammarterm{decl-specifier-seq} shall not
9398
define a class or enumeration. If the \keyword{auto} \grammarterm{type-specifier} appears in
9499
the \grammarterm{decl-specifier-seq},
95100
the type of the identifier being declared is deduced from the initializer as described in~\ref{dcl.spec.auto}.
96101

97102
\pnum
98-
The value of a \grammarterm{condition} that is an initialized declaration
103+
The \defn{decision variable} of a \grammarterm{condition}
104+
that is neither an \grammarterm{expression} nor a structured binding declaration
105+
is the declared variable.
106+
The decision variable of a \grammarterm{condition}
107+
that is a structured binding declaration is specified in\iref{dcl.struct.bind}.
108+
109+
\pnum
110+
The value of a \grammarterm{condition} that not an \grammarterm{expression}
99111
in a statement other than a \keyword{switch} statement is the value of the
100-
declared variable
112+
decision variable
101113
contextually converted to \tcode{bool}\iref{conv}.
102114
If that
103115
conversion is ill-formed, the program is ill-formed.
@@ -116,7 +128,10 @@
116128
it is interpreted as the latter.
117129

118130
\pnum
119-
In the \grammarterm{decl-specifier-seq} of a \grammarterm{condition}, each
131+
In the \grammarterm{decl-specifier-seq} of a \grammarterm{condition},
132+
including that of any \grammarterm{structured-binding-declaration} of
133+
the \grammarterm{condition},
134+
each
120135
\grammarterm{decl-specifier} shall be either a \grammarterm{type-specifier}
121136
or \keyword{constexpr}.
122137

@@ -408,10 +423,9 @@
408423
several statements depending on the value of a condition.
409424

410425
\pnum
411-
The value of a \grammarterm{condition}
412-
that is an initialized declaration
413-
is the value of the declared variable,
414-
or the value of the \grammarterm{expression} otherwise.
426+
If the \grammarterm{condition} is an \grammarterm{expression},
427+
the value of the condition is the value of the \grammarterm{expression};
428+
otherwise, it is the value of the decision variable.
415429
The value of the condition shall be of integral type, enumeration type, or class
416430
type. If of class type, the
417431
condition is contextually implicitly converted\iref{conv} to

0 commit comments

Comments
 (0)