Skip to content

Commit d92b0b2

Browse files
committed
[dcl.type.auto.deduct] Clarify initializer for placeholder type deduction.
1 parent fb6acaa commit d92b0b2

File tree

1 file changed

+45
-28
lines changed

1 file changed

+45
-28
lines changed

source/declarations.tex

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,8 +1709,6 @@
17091709
each of which shall
17101710
be followed by a non-empty
17111711
\grammarterm{initializer}.
1712-
If the \grammarterm{initializer} is a parenthesized \grammarterm{expression-list},
1713-
the \grammarterm{expression-list} shall be a single \grammarterm{assignment-expression}.
17141712
\begin{example}
17151713
\begin{codeblock}
17161714
auto x = 5; // OK: \tcode{x} has type \tcode{int}
@@ -1896,45 +1894,64 @@
18961894

18971895
\pnum
18981896
A type \tcode{T} containing a placeholder type,
1899-
and a corresponding initializer $E$,
1897+
and a corresponding \grammarterm{initializer-clause} $E$,
19001898
are determined as follows:
19011899
\begin{itemize}
19021900
\item
1903-
for a non-discarded \tcode{return} statement that occurs
1901+
For a non-discarded \tcode{return} statement that occurs
19041902
in a function declared with a return type
19051903
that contains a placeholder type,
1906-
\tcode{T} is the declared return type
1907-
and $E$ is the operand of the \tcode{return} statement.
1908-
If the \tcode{return} statement
1909-
has no operand,
1910-
then $E$ is \tcode{void()};
1904+
\tcode{T} is the declared return type.
1905+
\begin{itemize}
1906+
\item
1907+
If the \tcode{return} statement has no operand,
1908+
then $E$ is \tcode{void()}.
1909+
\item
1910+
If the operand is a \grammarterm{braced-init-list}\iref{dcl.init.list},
1911+
the program is ill-formed.
1912+
\item
1913+
If the operand is an \grammarterm{expression} $X$
1914+
that is not an \grammarterm{assignment-expression},
1915+
$E$ is \tcode{($X$)}.
1916+
\begin{note}
1917+
A comma expression\iref{expr.comma} is not
1918+
an \grammarterm{assignment-expression}.
1919+
\end{note}
19111920
\item
1912-
for a variable declared with a type
1921+
Otherwise, $E$ is the operand of the \tcode{return} statement.
1922+
\end{itemize}
1923+
If $E$ has type \keyword{void},
1924+
\tcode{T} shall be either
1925+
\opt{\grammarterm{type-constraint}} \tcode{decltype(auto)} or
1926+
\cv{}~\opt{\grammarterm{type-constraint}} \keyword{auto}.
1927+
\item
1928+
For a variable declared with a type
19131929
that contains a placeholder type,
1914-
\tcode{T} is the declared type of the variable
1915-
and $E$ is the initializer.
1916-
If the initialization is direct-list-initialization,
1917-
the initializer shall be a \grammarterm{braced-init-list}
1918-
containing only a single \grammarterm{assignment-expression}
1919-
and $E$ is the \grammarterm{assignment-expression};
1930+
\tcode{T} is the declared type of the variable.
1931+
\begin{itemize}
19201932
\item
1921-
for a non-type template parameter declared with a type
1933+
If the initializer of the variable is a \grammarterm{brace-or-equal-initializer}
1934+
of the form \tcode{= \grammarterm{initializer-clause}},
1935+
$E$ is the \grammarterm{initializer-clause}.
1936+
\item
1937+
If the initializer is a \grammarterm{braced-init-list},
1938+
it shall consist of a single brace-enclosed \grammarterm{initializer-clause}
1939+
and the \grammarterm{initializer-clause} shall be
1940+
an \grammarterm{assignment-expression},
1941+
and $E$ is the \grammarterm{assignment-expression}.
1942+
\item
1943+
If the initializer is a parenthesized \grammarterm{expression-list},
1944+
the \grammarterm{expression-list} shall be
1945+
a single \grammarterm{assignment-expression}
1946+
and $E$ is the \grammarterm{assignment-expression}.
1947+
\end{itemize}
1948+
\item
1949+
For a non-type template parameter declared with a type
19221950
that contains a placeholder type,
19231951
\tcode{T} is the declared type of the non-type template parameter
19241952
and $E$ is the corresponding template argument.
19251953
\end{itemize}
19261954

1927-
In the case of a \tcode{return} statement with no operand
1928-
or with an operand of type \keyword{void},
1929-
\tcode{T} shall be either
1930-
\opt{\grammarterm{type-constraint}} \tcode{decltype(auto)} or
1931-
\cv{}~\opt{\grammarterm{type-constraint}} \keyword{auto}.
1932-
1933-
\pnum
1934-
If the deduction is for a \tcode{return} statement
1935-
and $E$ is a \grammarterm{braced-init-list}\iref{dcl.init.list},
1936-
the program is ill-formed.
1937-
19381955
\pnum
19391956
If the \grammarterm{placeholder-type-specifier} is of the form
19401957
\opt{\grammarterm{type-constraint}} \keyword{auto},

0 commit comments

Comments
 (0)