Skip to content

Commit 4045c67

Browse files
committed
[dcl.type.auto.deduct] Clarify initializer for placeholder type deduction.
1 parent b8e9549 commit 4045c67

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

source/declarations.tex

+43-27
Original file line numberDiff line numberDiff line change
@@ -1718,8 +1718,6 @@
17181718
each of which shall
17191719
be followed by a non-empty
17201720
\grammarterm{initializer}.
1721-
If the \grammarterm{initializer} is a parenthesized \grammarterm{expression-list},
1722-
the \grammarterm{expression-list} shall be a single \grammarterm{assignment-expression}.
17231721
\begin{example}
17241722
\begin{codeblock}
17251723
auto x = 5; // OK: \tcode{x} has type \tcode{int}
@@ -1905,45 +1903,63 @@
19051903

19061904
\pnum
19071905
A type \tcode{T} containing a placeholder type,
1908-
and a corresponding initializer $E$,
1906+
and a corresponding \grammarterm{initializer-clause} $E$,
19091907
are determined as follows:
19101908
\begin{itemize}
19111909
\item
1912-
for a non-discarded \tcode{return} statement that occurs
1910+
For a non-discarded \tcode{return} statement that occurs
19131911
in a function declared with a return type
19141912
that contains a placeholder type,
1915-
\tcode{T} is the declared return type
1916-
and $E$ is the operand of the \tcode{return} statement.
1917-
If the \tcode{return} statement
1918-
has no operand,
1919-
then $E$ is \tcode{void()};
1913+
\tcode{T} is the declared return type.
1914+
\begin{itemize}
1915+
\item
1916+
If the \tcode{return} statement has no operand,
1917+
then $E$ is \tcode{void()}.
1918+
\item
1919+
If the operand is a \grammarterm{braced-init-list}\iref{dcl.init.list},
1920+
the program is ill-formed.
1921+
\item
1922+
If the operand is an \grammarterm{expression} $X$
1923+
that is not an \grammarterm{assignment-expression},
1924+
$E$ is \tcode{($X$)}.
1925+
\begin{note}
1926+
A comma expression\iref{expr.comma} is not
1927+
an \grammarterm{assignment-expression}.
1928+
\end{note}
1929+
\item
1930+
Otherwise, $E$ is the operand of the \tcode{return} statement.
1931+
\end{itemize}
1932+
If $E$ has type \keyword{void},
1933+
\tcode{T} shall be either
1934+
\opt{\grammarterm{type-constraint}} \tcode{decltype(auto)} or
1935+
\cv{}~\opt{\grammarterm{type-constraint}} \keyword{auto}.
19201936
\item
1921-
for a variable declared with a type
1937+
For a variable declared with a type
19221938
that contains a placeholder type,
1923-
\tcode{T} is the declared type of the variable
1924-
and $E$ is the initializer.
1925-
If the initialization is direct-list-initialization,
1926-
the initializer shall be a \grammarterm{braced-init-list}
1927-
containing only a single \grammarterm{assignment-expression}
1928-
and $E$ is the \grammarterm{assignment-expression};
1939+
\tcode{T} is the declared type of the variable.
1940+
\begin{itemize}
1941+
\item
1942+
If the initializer of the variable is a \grammarterm{brace-or-equal-initializer}
1943+
of the form \tcode{= \grammarterm{initializer-clause}},
1944+
$E$ is the \grammarterm{initializer-clause}.
1945+
\item
1946+
If the initializer is a \grammarterm{braced-init-list},
1947+
it shall consist of a single brace-enclosed \grammarterm{assignment-expression}
1948+
and $E$ is the \grammarterm{assignment-expression}.
1949+
\item
1950+
If the initializer is a parenthesized \grammarterm{expression-list},
1951+
the \grammarterm{expression-list} shall be
1952+
a single \grammarterm{assignment-expression}
1953+
and $E$ is the \grammarterm{assignment-expression}.
1954+
\end{itemize}
19291955
\item
1930-
for a non-type template parameter declared with a type
1956+
For a non-type template parameter declared with a type
19311957
that contains a placeholder type,
19321958
\tcode{T} is the declared type of the non-type template parameter
19331959
and $E$ is the corresponding template argument.
19341960
\end{itemize}
19351961

19361962
\tcode{T} shall not be an array type.
1937-
In the case of a \tcode{return} statement with no operand
1938-
or with an operand of type \keyword{void},
1939-
\tcode{T} shall be either
1940-
\opt{\grammarterm{type-constraint}} \tcode{decltype(auto)} or
1941-
\cv{}~\opt{\grammarterm{type-constraint}} \keyword{auto}.
1942-
1943-
\pnum
1944-
If the deduction is for a \tcode{return} statement
1945-
and $E$ is a \grammarterm{braced-init-list}\iref{dcl.init.list},
1946-
the program is ill-formed.
19471963

19481964
\pnum
19491965
If the \grammarterm{placeholder-type-specifier} is of the form

0 commit comments

Comments
 (0)