Skip to content

[dcl.type.auto.deduct] Clarify initializer for placeholder type deduction. #4315

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
Jun 22, 2021
Merged
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
70 changes: 43 additions & 27 deletions source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1718,8 +1718,6 @@
each of which shall
be followed by a non-empty
\grammarterm{initializer}.
If the \grammarterm{initializer} is a parenthesized \grammarterm{expression-list},
the \grammarterm{expression-list} shall be a single \grammarterm{assignment-expression}.
\begin{example}
\begin{codeblock}
auto x = 5; // OK: \tcode{x} has type \tcode{int}
Expand Down Expand Up @@ -1905,45 +1903,63 @@

\pnum
A type \tcode{T} containing a placeholder type,
and a corresponding initializer $E$,
and a corresponding \grammarterm{initializer-clause} $E$,
are determined as follows:
\begin{itemize}
\item
for a non-discarded \tcode{return} statement that occurs
For a non-discarded \tcode{return} statement that occurs
in a function declared with a return type
that contains a placeholder type,
\tcode{T} is the declared return type
and $E$ is the operand of the \tcode{return} statement.
If the \tcode{return} statement
has no operand,
then $E$ is \tcode{void()};
\tcode{T} is the declared return type.
\begin{itemize}
\item
If the \tcode{return} statement has no operand,
then $E$ is \tcode{void()}.
\item
If the operand is a \grammarterm{braced-init-list}\iref{dcl.init.list},
the program is ill-formed.
\item
If the operand is an \grammarterm{expression} $X$
that is not an \grammarterm{assignment-expression},
$E$ is \tcode{($X$)}.
\begin{note}
A comma expression\iref{expr.comma} is not
an \grammarterm{assignment-expression}.
\end{note}
\item
Otherwise, $E$ is the operand of the \tcode{return} statement.
\end{itemize}
If $E$ has type \keyword{void},
\tcode{T} shall be either
\opt{\grammarterm{type-constraint}} \tcode{decltype(auto)} or
\cv{}~\opt{\grammarterm{type-constraint}} \keyword{auto}.
\item
for a variable declared with a type
For a variable declared with a type
that contains a placeholder type,
\tcode{T} is the declared type of the variable
and $E$ is the initializer.
If the initialization is direct-list-initialization,
the initializer shall be a \grammarterm{braced-init-list}
containing only a single \grammarterm{assignment-expression}
and $E$ is the \grammarterm{assignment-expression};
\tcode{T} is the declared type of the variable.
\begin{itemize}
\item
If the initializer of the variable is a \grammarterm{brace-or-equal-initializer}
of the form \tcode{= \grammarterm{initializer-clause}},
$E$ is the \grammarterm{initializer-clause}.
\item
If the initializer is a \grammarterm{braced-init-list},
it shall consist of a single brace-enclosed \grammarterm{assignment-expression}
and $E$ is the \grammarterm{assignment-expression}.
\item
If the initializer is a parenthesized \grammarterm{expression-list},
the \grammarterm{expression-list} shall be
a single \grammarterm{assignment-expression}
and $E$ is the \grammarterm{assignment-expression}.
\end{itemize}
\item
for a non-type template parameter declared with a type
For a non-type template parameter declared with a type
that contains a placeholder type,
\tcode{T} is the declared type of the non-type template parameter
and $E$ is the corresponding template argument.
\end{itemize}

\tcode{T} shall not be an array type.
In the case of a \tcode{return} statement with no operand
or with an operand of type \keyword{void},
\tcode{T} shall be either
\opt{\grammarterm{type-constraint}} \tcode{decltype(auto)} or
\cv{}~\opt{\grammarterm{type-constraint}} \keyword{auto}.

\pnum
If the deduction is for a \tcode{return} statement
and $E$ is a \grammarterm{braced-init-list}\iref{dcl.init.list},
the program is ill-formed.

\pnum
If the \grammarterm{placeholder-type-specifier} is of the form
Expand Down