Skip to content

Commit ee919d0

Browse files
committed
P0620R0 Drafting for class template argument deduction issues
[dcl.spec.auto] Replace "have an initializer" with "be followed by an initializer", to match the change from "init-declarator" to "declarator". [dcl.type.class.deduct] Add paragraph break between new paragraph and example (the example is for the entire section, not for the new para). [expr.new] Rename placeholder from I to init to improve appearance of following code snippet.
1 parent 49caa2b commit ee919d0

File tree

5 files changed

+121
-69
lines changed

5 files changed

+121
-69
lines changed

source/declarations.tex

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,17 +1284,14 @@
12841284
\indextext{type specifier!\idxcode{decltype}}%
12851285
\indextext{\idxgram{type-name}}%
12861286
\indextext{\idxgram{lambda-introducer}}%
1287-
The \grammarterm{simple-type-specifier} \tcode{auto} is a placeholder for a type to be
1288-
deduced~(\ref{dcl.spec.auto}).
1287+
The \grammarterm{simple-type-specifier} \tcode{auto}
1288+
is a placeholder for
1289+
a type to be deduced~(\ref{dcl.spec.auto}).
12891290
\indextext{deduction!class template arguments}%
12901291
A \grammarterm{type-specifier} of the form
12911292
\tcode{typename}\opt{} \grammarterm{nested-name-specifier}\opt{} \grammarterm{template-name}
1292-
is a placeholder for a deduced class type
1293-
and shall appear only as a \grammarterm{decl-specifier}
1294-
in the \grammarterm{decl-specifier-seq}
1295-
of a \grammarterm{simple-declaration}~(\ref{dcl.type.class.deduct})
1296-
or as the \grammarterm{simple-type-specifier}
1297-
in an explicit type conversion (functional notation)~(\ref{expr.type.conv}).
1293+
is a placeholder for
1294+
a deduced class type~(\ref{dcl.type.class.deduct}).
12981295
The \grammarterm{template-name} shall name a class template
12991296
that is not an injected-class-name.
13001297
The other
@@ -1585,20 +1582,22 @@
15851582

15861583
\pnum
15871584
The type of a variable declared using \tcode{auto} or \tcode{decltype(auto)} is
1588-
deduced from its initializer. This use is allowed when declaring variables in a
1589-
block~(\ref{stmt.block}), in
1590-
namespace scope~(\ref{basic.scope.namespace}), and in an
1591-
\grammarterm{init-statement} (Clause~\ref{stmt.stmt}).
1585+
deduced from its initializer.
1586+
This use is allowed
1587+
in an initializing declaration~(\ref{dcl.init}) of a variable.
15921588
\tcode{auto} or \tcode{decltype(auto)} shall appear as one of the
15931589
\grammarterm{decl-specifier}{s} in the
15941590
\grammarterm{decl-specifier-seq} and the
15951591
\grammarterm{decl-specifier-seq}
1596-
shall be followed by one or more \grammarterm{init-declarator}{s}, each of which shall
1597-
have a non-empty \grammarterm{initializer}. In an
1598-
\grammarterm{initializer} of the form
1592+
shall be followed by one or more
1593+
\grammarterm{declarator}{s},
1594+
each of which shall
1595+
be followed by a non-empty
1596+
\grammarterm{initializer}.
1597+
In an \grammarterm{initializer} of the form
15991598

16001599
\begin{codeblock}
1601-
( @\grammarterm{expression-list}@ )
1600+
( @\textrm{\grammarterm{expression-list}}@ )
16021601
\end{codeblock}
16031602

16041603
the \grammarterm{expression-list} shall be a single
@@ -1616,15 +1615,10 @@
16161615
\end{example}
16171616

16181617
\pnum
1619-
A placeholder type can also be used in declaring a variable in
1620-
the \grammarterm{condition} of a selection statement~(\ref{stmt.select}) or an iteration
1621-
statement~(\ref{stmt.iter}), in the \grammarterm{type-specifier-seq} in
1618+
A placeholder type can also be used
1619+
in the \grammarterm{type-specifier-seq} in
16221620
the \grammarterm{new-type-id} or \grammarterm{type-id} of a
1623-
\grammarterm{new-expression}~(\ref{expr.new}), in a
1624-
\grammarterm{for-range-declaration},
1625-
in declaring a static data member with a
1626-
\grammarterm{brace-or-equal-initializer} that appears within the
1627-
\grammarterm{member-specification} of a class definition~(\ref{class.static.data}),
1621+
\grammarterm{new-expression}~(\ref{expr.new})
16281622
and as a \grammarterm{decl-specifier}
16291623
of the \grammarterm{parameter-declaration}{'s}
16301624
\grammarterm{decl-specifier-seq}
@@ -1873,21 +1867,29 @@
18731867
If a placeholder for a deduced class type
18741868
appears as a \grammarterm{decl-specifier}
18751869
in the \grammarterm{decl-specifier-seq}
1876-
of a \grammarterm{simple-declaration},
1877-
the \grammarterm{init-declarator}
1878-
of that declaration
1879-
shall be of the form
1880-
1881-
\begin{ncbnf}
1882-
declarator-id attribute-specifier-seq\opt{} initializer
1883-
\end{ncbnf}
1884-
1885-
The placeholder is replaced by the return type
1870+
of an initializing declaration~(\ref{dcl.init}) of a variable,
1871+
the placeholder is replaced by the return type
18861872
of the function selected by overload resolution
18871873
for class template deduction~(\ref{over.match.class.deduct}).
1888-
If the \grammarterm{init-declarator-list}
1889-
contains more than one \grammarterm{init-declarator},
1874+
If the \grammarterm{decl-specifier-seq}
1875+
is followed by an \grammarterm{init-declarator-list}
1876+
or \grammarterm{member-declarator-list}
1877+
containing more than one \grammarterm{declarator},
18901878
the type that replaces the placeholder shall be the same in each deduction.
1879+
1880+
\pnum
1881+
A placeholder for a deduced class type
1882+
can also be used
1883+
in the \grammarterm{type-specifier-seq}
1884+
in the \grammarterm{new-type-id} or \grammarterm{type-id}
1885+
of a \grammarterm{new-expression}~(\ref{expr.new}),
1886+
or
1887+
as the \grammarterm{simple-type-specifier}
1888+
in an explicit type conversion (functional notation)~(\ref{expr.type.conv}).
1889+
A placeholder for a deduced class type
1890+
shall not appear in any other context.
1891+
1892+
\pnum
18911893
\begin{example}
18921894
\begin{codeblock}
18931895
template<class T> struct container {

source/declarators.tex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,19 @@
28932893
or by an inherited constructor~(\ref{class.inhctor.init}).
28942894
\end{note}
28952895

2896+
\pnum
2897+
A declaration that specifies the initialization of a variable,
2898+
whether from an explicit initializer or by default-initialization,
2899+
is called the \defn{initializing declaration} of that variable.
2900+
\begin{note}
2901+
In most cases
2902+
this is the defining declaration~(\ref{basic.def}) of the variable,
2903+
but the initializing declaration
2904+
of a non-inline static data member~(\ref{class.static.data})
2905+
might be the declaration within the class definition
2906+
and not the definition at namespace scope.
2907+
\end{note}
2908+
28962909
\rSec2[dcl.init.aggr]{Aggregates}%
28972910
\indextext{aggregate}%
28982911
\indextext{initialization!aggregate}%

source/expressions.tex

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,28 +3029,26 @@
30293029
If a placeholder type~(\ref{dcl.spec.auto}) appears in the
30303030
\grammarterm{type-specifier-seq} of a \grammarterm{new-type-id} or
30313031
\grammarterm{type-id} of a \grammarterm{new-expression},
3032-
the \grammarterm{new-expression} shall contain a
3033-
\grammarterm{new-initializer} of the form
3034-
3035-
\begin{ncsimplebnf}
3036-
\terminal{(} assignment-expression \terminal{)}
3037-
\end{ncsimplebnf}
3038-
3039-
The allocated type is deduced from the \grammarterm{new-initializer} as
3040-
follows: Let \tcode{e} be the \grammarterm{assignment-expression} in the \grammarterm{new-initializer} and
3032+
the allocated type is deduced as follows:
3033+
Let
3034+
\placeholder{init} be the \grammarterm{new-initializer}, if any,
3035+
and
30413036
\tcode{T} be the \grammarterm{new-type-id} or \grammarterm{type-id} of
30423037
the \grammarterm{new-expression}, then the allocated type is the type
30433038
deduced for the variable \tcode{x} in the invented
30443039
declaration~(\ref{dcl.spec.auto}):
30453040

30463041
\begin{codeblock}
3047-
T x(e);
3042+
T x @\textrm{\placeholder{init}}@ ;
30483043
\end{codeblock}
30493044

30503045
\begin{example}
30513046
\begin{codeblock}
30523047
new auto(1); // allocated type is \tcode{int}
30533048
auto x = new auto('a'); // allocated type is \tcode{char}, \tcode{x} is of type \tcode{char*}
3049+
3050+
template<class T> struct A { A(T, T); };
3051+
auto y = new A{1, 2}; // allocated type is \tcode{A<int>}
30543052
\end{codeblock}
30553053
\end{example}
30563054

source/overloading.tex

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,8 +1392,9 @@
13921392
\begin{itemize}
13931393
\item
13941394
For each constructor
1395-
of the class template
1395+
of the primary class template
13961396
designated by the \grammarterm{template-name},
1397+
if the template is defined,
13971398
a function template with the following properties:
13981399
\begin{itemize}
13991400
\item
@@ -1411,6 +1412,17 @@
14111412
obtained from the class template.
14121413
\end{itemize}
14131414

1415+
\item
1416+
If the primary class template \tcode{C}
1417+
is not defined or does not declare any constructors,
1418+
an additional function template derived as above
1419+
from a hypothetical constructor \tcode{C()}.
1420+
1421+
\item
1422+
An additional function template derived as above
1423+
from a hypothetical constructor \tcode{C(C)},
1424+
called the \defn{copy deduction candidate}.
1425+
14141426
\item
14151427
For each \grammarterm{deduction-guide},
14161428
a function or function template
@@ -1440,6 +1452,8 @@
14401452
is considered to be explicit if the function or function template was
14411453
generated from a constructor or \grammarterm{deduction-guide} that was
14421454
declared \tcode{explicit}.
1455+
All such notional constructors are considered to be
1456+
public members of the hypothetical class type.
14431457

14441458
\pnum
14451459
\begin{example}
@@ -1640,26 +1654,6 @@
16401654
\end{example}
16411655
or, if not that,
16421656

1643-
\item
1644-
\tcode{F1} is generated from a
1645-
\grammarterm{deduction-guide}~(\ref{over.match.class.deduct})
1646-
and \tcode{F2} is not
1647-
\begin{example}
1648-
\begin{codeblock}
1649-
template <class T> struct A {
1650-
A(T, int*); // \#1
1651-
A(A<T>&, int*); // \#2
1652-
enum { value };
1653-
};
1654-
1655-
template <class T, int N = T::value> A(T&&, int*) -> A<T>; // \#3
1656-
1657-
A a{1, 0}; // uses \#1 to deduce \tcode{A<int>} and initializes with \#1
1658-
A b{a, 0}; // uses \#3 (not \#2) to deduce \tcode{A<A<int>\&>} and initializes with \#1
1659-
\end{codeblock}
1660-
\end{example}
1661-
or, if not that,
1662-
16631657
\item
16641658
\tcode{F1}
16651659
is not a function template specialization and
@@ -1679,7 +1673,47 @@
16791673
\tcode{F1}
16801674
is more specialized than the template for
16811675
\tcode{F2}
1682-
according to the partial ordering rules described in~\ref{temp.func.order}.
1676+
according to the partial ordering rules described in~\ref{temp.func.order},
1677+
or, if not that,
1678+
1679+
\item
1680+
\tcode{F1} is generated from a
1681+
\grammarterm{deduction-guide}~(\ref{over.match.class.deduct})
1682+
and \tcode{F2} is not, or, if not that,
1683+
1684+
\item
1685+
\tcode{F1} is the copy deduction candidate~(\ref{over.match.class.deduct})
1686+
and \tcode{F2} is not, or, if not that,
1687+
1688+
\item
1689+
\tcode{F1} is generated from a non-template constructor
1690+
and \tcode{F2} is generated from a constructor template.
1691+
\begin{example}
1692+
\begin{codeblock}
1693+
template <class T> struct A {
1694+
using value_type = T;
1695+
A(value_type); // \#1
1696+
A(const A&); // \#2
1697+
A(T, T, int); // \#3
1698+
template<class U>
1699+
A(int, T, U); // \#4
1700+
// \#5, \tcode{A(A)}, the copy deduction candidate
1701+
};
1702+
1703+
A x(1, 2, 3); // uses \#3, generated from a non-template constructor
1704+
1705+
template <class T>
1706+
A(T) -> A<T>; // \#6, less specialized than \#5
1707+
1708+
A a(42); // uses \#6 to deduce \tcode{A<int>} and \#1 to initialize
1709+
A b = a; // uses \#5 to deduce \tcode{A<int>} and \#2 to initialize
1710+
1711+
template <class T>
1712+
A(A<T>) -> A<A<T>>; // \#7, as specialized as \#5
1713+
1714+
A b2 = a; // uses \#7 to deduce \tcode{A<A<int>>} and \#1 to initialize
1715+
\end{codeblock}
1716+
\end{example}
16831717
\end{itemize}
16841718

16851719
\pnum

source/templates.tex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7652,6 +7652,11 @@
76527652
A \grammarterm{deduction-guide}
76537653
shall be declared
76547654
in the same scope
7655-
as the corresponding class template.
7655+
as the corresponding class template
7656+
and, for a member class template, with the same access.
7657+
Two deduction guide declarations
7658+
in the same translation unit
7659+
for the same class template
7660+
shall not have equivalent \grammarterm{parameter-declaration-clause}{s}.
76567661

76577662
\indextext{template|)}

0 commit comments

Comments
 (0)