Skip to content

Commit e5be945

Browse files
committed
Merge 2017-03 CWG Motion 8
2 parents bd109b5 + 2820859 commit e5be945

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
@@ -1277,17 +1277,14 @@
12771277
\indextext{type specifier!\idxcode{decltype}}%
12781278
\indextext{\idxgram{type-name}}%
12791279
\indextext{\idxgram{lambda-introducer}}%
1280-
The \grammarterm{simple-type-specifier} \tcode{auto} is a placeholder for a type to be
1281-
deduced~(\ref{dcl.spec.auto}).
1280+
The \grammarterm{simple-type-specifier} \tcode{auto}
1281+
is a placeholder for
1282+
a type to be deduced~(\ref{dcl.spec.auto}).
12821283
\indextext{deduction!class template arguments}%
12831284
A \grammarterm{type-specifier} of the form
12841285
\tcode{typename}\opt{} \grammarterm{nested-name-specifier}\opt{} \grammarterm{template-name}
1285-
is a placeholder for a deduced class type
1286-
and shall appear only as a \grammarterm{decl-specifier}
1287-
in the \grammarterm{decl-specifier-seq}
1288-
of a \grammarterm{simple-declaration}~(\ref{dcl.type.class.deduct})
1289-
or as the \grammarterm{simple-type-specifier}
1290-
in an explicit type conversion (functional notation)~(\ref{expr.type.conv}).
1286+
is a placeholder for
1287+
a deduced class type~(\ref{dcl.type.class.deduct}).
12911288
The \grammarterm{template-name} shall name a class template
12921289
that is not an injected-class-name.
12931290
The other
@@ -1578,20 +1575,22 @@
15781575

15791576
\pnum
15801577
The type of a variable declared using \tcode{auto} or \tcode{decltype(auto)} is
1581-
deduced from its initializer. This use is allowed when declaring variables in a
1582-
block~(\ref{stmt.block}), in
1583-
namespace scope~(\ref{basic.scope.namespace}), and in an
1584-
\grammarterm{init-statement} (Clause~\ref{stmt.stmt}).
1578+
deduced from its initializer.
1579+
This use is allowed
1580+
in an initializing declaration~(\ref{dcl.init}) of a variable.
15851581
\tcode{auto} or \tcode{decltype(auto)} shall appear as one of the
15861582
\grammarterm{decl-specifier}{s} in the
15871583
\grammarterm{decl-specifier-seq} and the
15881584
\grammarterm{decl-specifier-seq}
1589-
shall be followed by one or more \grammarterm{init-declarator}{s}, each of which shall
1590-
have a non-empty \grammarterm{initializer}. In an
1591-
\grammarterm{initializer} of the form
1585+
shall be followed by one or more
1586+
\grammarterm{declarator}{s},
1587+
each of which shall
1588+
be followed by a non-empty
1589+
\grammarterm{initializer}.
1590+
In an \grammarterm{initializer} of the form
15921591

15931592
\begin{codeblock}
1594-
( @\grammarterm{expression-list}@ )
1593+
( @\textrm{\grammarterm{expression-list}}@ )
15951594
\end{codeblock}
15961595

15971596
the \grammarterm{expression-list} shall be a single
@@ -1609,15 +1608,10 @@
16091608
\end{example}
16101609

16111610
\pnum
1612-
A placeholder type can also be used in declaring a variable in
1613-
the \grammarterm{condition} of a selection statement~(\ref{stmt.select}) or an iteration
1614-
statement~(\ref{stmt.iter}), in the \grammarterm{type-specifier-seq} in
1611+
A placeholder type can also be used
1612+
in the \grammarterm{type-specifier-seq} in
16151613
the \grammarterm{new-type-id} or \grammarterm{type-id} of a
1616-
\grammarterm{new-expression}~(\ref{expr.new}), in a
1617-
\grammarterm{for-range-declaration},
1618-
in declaring a static data member with a
1619-
\grammarterm{brace-or-equal-initializer} that appears within the
1620-
\grammarterm{member-specification} of a class definition~(\ref{class.static.data}),
1614+
\grammarterm{new-expression}~(\ref{expr.new})
16211615
and as a \grammarterm{decl-specifier}
16221616
of the \grammarterm{parameter-declaration}{'s}
16231617
\grammarterm{decl-specifier-seq}
@@ -1866,21 +1860,29 @@
18661860
If a placeholder for a deduced class type
18671861
appears as a \grammarterm{decl-specifier}
18681862
in the \grammarterm{decl-specifier-seq}
1869-
of a \grammarterm{simple-declaration},
1870-
the \grammarterm{init-declarator}
1871-
of that declaration
1872-
shall be of the form
1873-
1874-
\begin{ncbnf}
1875-
declarator-id attribute-specifier-seq\opt{} initializer
1876-
\end{ncbnf}
1877-
1878-
The placeholder is replaced by the return type
1863+
of an initializing declaration~(\ref{dcl.init}) of a variable,
1864+
the placeholder is replaced by the return type
18791865
of the function selected by overload resolution
18801866
for class template deduction~(\ref{over.match.class.deduct}).
1881-
If the \grammarterm{init-declarator-list}
1882-
contains more than one \grammarterm{init-declarator},
1867+
If the \grammarterm{decl-specifier-seq}
1868+
is followed by an \grammarterm{init-declarator-list}
1869+
or \grammarterm{member-declarator-list}
1870+
containing more than one \grammarterm{declarator},
18831871
the type that replaces the placeholder shall be the same in each deduction.
1872+
1873+
\pnum
1874+
A placeholder for a deduced class type
1875+
can also be used
1876+
in the \grammarterm{type-specifier-seq}
1877+
in the \grammarterm{new-type-id} or \grammarterm{type-id}
1878+
of a \grammarterm{new-expression}~(\ref{expr.new}),
1879+
or
1880+
as the \grammarterm{simple-type-specifier}
1881+
in an explicit type conversion (functional notation)~(\ref{expr.type.conv}).
1882+
A placeholder for a deduced class type
1883+
shall not appear in any other context.
1884+
1885+
\pnum
18841886
\begin{example}
18851887
\begin{codeblock}
18861888
template<class T> struct container {

source/declarators.tex

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

2911+
\pnum
2912+
A declaration that specifies the initialization of a variable,
2913+
whether from an explicit initializer or by default-initialization,
2914+
is called the \defn{initializing declaration} of that variable.
2915+
\begin{note}
2916+
In most cases
2917+
this is the defining declaration~(\ref{basic.def}) of the variable,
2918+
but the initializing declaration
2919+
of a non-inline static data member~(\ref{class.static.data})
2920+
might be the declaration within the class definition
2921+
and not the definition at namespace scope.
2922+
\end{note}
2923+
29112924
\rSec2[dcl.init.aggr]{Aggregates}%
29122925
\indextext{aggregate}%
29132926
\indextext{initialization!aggregate}%

source/expressions.tex

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,28 +3061,26 @@
30613061
If a placeholder type~(\ref{dcl.spec.auto}) appears in the
30623062
\grammarterm{type-specifier-seq} of a \grammarterm{new-type-id} or
30633063
\grammarterm{type-id} of a \grammarterm{new-expression},
3064-
the \grammarterm{new-expression} shall contain a
3065-
\grammarterm{new-initializer} of the form
3066-
3067-
\begin{ncsimplebnf}
3068-
\terminal{(} assignment-expression \terminal{)}
3069-
\end{ncsimplebnf}
3070-
3071-
The allocated type is deduced from the \grammarterm{new-initializer} as
3072-
follows: Let \tcode{e} be the \grammarterm{assignment-expression} in the \grammarterm{new-initializer} and
3064+
the allocated type is deduced as follows:
3065+
Let
3066+
\placeholder{init} be the \grammarterm{new-initializer}, if any,
3067+
and
30733068
\tcode{T} be the \grammarterm{new-type-id} or \grammarterm{type-id} of
30743069
the \grammarterm{new-expression}, then the allocated type is the type
30753070
deduced for the variable \tcode{x} in the invented
30763071
declaration~(\ref{dcl.spec.auto}):
30773072

30783073
\begin{codeblock}
3079-
T x(e);
3074+
T x @\textrm{\placeholder{init}}@ ;
30803075
\end{codeblock}
30813076

30823077
\begin{example}
30833078
\begin{codeblock}
30843079
new auto(1); // allocated type is \tcode{int}
30853080
auto x = new auto('a'); // allocated type is \tcode{char}, \tcode{x} is of type \tcode{char*}
3081+
3082+
template<class T> struct A { A(T, T); };
3083+
auto y = new A{1, 2}; // allocated type is \tcode{A<int>}
30863084
\end{codeblock}
30873085
\end{example}
30883086

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 is the copy deduction candidate, \tcode{A(A)}
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
@@ -7657,6 +7657,11 @@
76577657
A \grammarterm{deduction-guide}
76587658
shall be declared
76597659
in the same scope
7660-
as the corresponding class template.
7660+
as the corresponding class template
7661+
and, for a member class template, with the same access.
7662+
Two deduction guide declarations
7663+
in the same translation unit
7664+
for the same class template
7665+
shall not have equivalent \grammarterm{parameter-declaration-clause}{s}.
76617666

76627667
\indextext{template|)}

0 commit comments

Comments
 (0)