Skip to content

[CWG motion 7 2024-06] P0963R3 Structured binding declaration as a condition #7112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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$.
Expand Down
34 changes: 24 additions & 10 deletions source/statements.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -86,18 +87,29 @@
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
the \grammarterm{decl-specifier-seq},
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.
Expand All @@ -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}.

Expand Down Expand Up @@ -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
Expand Down
Loading