From Jason Turner

[temp.arg]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpof86zni8/{from.md → to.md} +37 -31
tmp/tmpof86zni8/{from.md → to.md} RENAMED
@@ -1,7 +1,9 @@
1
  ## Template arguments <a id="temp.arg">[[temp.arg]]</a>
2
 
 
 
3
  There are three forms of *template-argument*, corresponding to the three
4
  forms of *template-parameter*: type, non-type and template. The type and
5
  form of each *template-argument* specified in a *template-id* shall
6
  match the type and form specified for the corresponding parameter
7
  declared by the template in its *template-parameter-list*. When the
@@ -32,10 +34,17 @@ void bar() {
32
  }
33
  ```
34
 
35
  — *end example*]
36
 
 
 
 
 
 
 
 
37
  In a *template-argument*, an ambiguity between a *type-id* and an
38
  expression is resolved to a *type-id*, regardless of the form of the
39
  corresponding *template-parameter*.[^3]
40
 
41
  [*Example 2*:
@@ -49,17 +58,13 @@ void g() {
49
  }
50
  ```
51
 
52
  — *end example*]
53
 
54
- The name of a *template-argument* shall be accessible at the point where
55
- it is used as a *template-argument*.
56
-
57
- [*Note 1*: If the name of the *template-argument* is accessible at the
58
- point where it is used as a *template-argument*, there is no further
59
- access restriction in the resulting instantiation where the
60
- corresponding *template-parameter* name is used. — *end note*]
61
 
62
  [*Example 3*:
63
 
64
  ``` cpp
65
  template<class T> class X {
@@ -67,13 +72,13 @@ template<class T> class X {
67
  };
68
 
69
  class Y {
70
  private:
71
  struct S { ... };
72
- X<S> x; // OK: S is accessible
73
  // X<Y::S> has a static member of type Y::S
74
- // OK: even though Y::S is private
75
  };
76
 
77
  X<Y::S> y; // error: S not accessible
78
  ```
79
 
@@ -106,14 +111,14 @@ brackets shall still be used as the *template-argument-list*.
106
 
107
  [*Example 5*:
108
 
109
  ``` cpp
110
  template<class T = char> class String;
111
- String<>* p; // OK: String<char>
112
  String* q; // syntax error
113
  template<class ... Elements> class Tuple;
114
- Tuple<>* t; // OK: Elements is empty
115
  Tuple* u; // syntax error
116
  ```
117
 
118
  — *end example*]
119
 
@@ -126,26 +131,28 @@ that is a class template specialization may explicitly specify the
126
  ``` cpp
127
  template<class T> struct A {
128
  ~A();
129
  };
130
  void f(A<int>* p, A<int>* q) {
131
- p->A<int>::~A(); // OK: destructor call
132
- q->A<int>::~A<int>(); // OK: destructor call
133
  }
134
  ```
135
 
136
  — *end example*]
137
 
138
  If the use of a *template-argument* gives rise to an ill-formed
139
  construct in the instantiation of a template specialization, the program
140
  is ill-formed.
141
 
142
- When name lookup for the name in a *template-id* finds an overload set,
143
- both non-template functions in the overload set and function templates
144
- in the overload set for which the *template-argument*s do not match the
145
- *template-parameter*s are ignored. If none of the function templates
146
- have matching *template-parameter*s, the program is ill-formed.
 
 
147
 
148
  When a *simple-template-id* does not name a function, a default
149
  *template-argument* is implicitly instantiated [[temp.inst]] when the
150
  value of that default argument is needed.
151
 
@@ -190,12 +197,12 @@ void f() {
190
  }
191
  ```
192
 
193
  — *end example*]
194
 
195
- [*Note 1*: A template type argument may be an incomplete type
196
- [[basic.types]]. — *end note*]
197
 
198
  ### Template non-type arguments <a id="temp.arg.nontype">[[temp.arg.nontype]]</a>
199
 
200
  If the type `T` of a *template-parameter* [[temp.param]] contains a
201
  placeholder type [[dcl.spec.auto]] or a placeholder for a deduced class
@@ -317,22 +324,21 @@ C<Y{X{1}.n}> c; // error: subobject of temporary object used to
317
 
318
  ### Template template arguments <a id="temp.arg.template">[[temp.arg.template]]</a>
319
 
320
  A *template-argument* for a template *template-parameter* shall be the
321
  name of a class template or an alias template, expressed as
322
- *id-expression*. When the *template-argument* names a class template,
323
- only primary class templates are considered when matching the template
324
- template argument with the corresponding parameter; partial
325
  specializations are not considered even if their parameter lists match
326
  that of the template template parameter.
327
 
328
- Any partial specializations [[temp.class.spec]] associated with the
329
- primary class template or primary variable template are considered when
330
- a specialization based on the template *template-parameter* is
331
- instantiated. If a specialization is not visible at the point of
332
- instantiation, and it would have been selected had it been visible, the
333
- program is ill-formed, no diagnostic required.
334
 
335
  [*Example 1*:
336
 
337
  ``` cpp
338
  template<class T> class A { // primary template
@@ -402,12 +408,12 @@ template <class T1> struct A;
402
  template <class T1, class T2> struct B;
403
  template <int N> struct C;
404
  template <class T1, int N> struct D;
405
  template <class T1, class T2, int N = 17> struct E;
406
 
407
- eval<A<int>> eA; // OK: matches partial specialization of eval
408
- eval<B<int, float>> eB; // OK: matches partial specialization of eval
409
  eval<C<17>> eC; // error: C does not match TT in partial specialization
410
  eval<D<int, 17>> eD; // error: D does not match TT in partial specialization
411
  eval<E<int, float>> eE; // error: E does not match TT in partial specialization
412
  ```
413
 
 
1
  ## Template arguments <a id="temp.arg">[[temp.arg]]</a>
2
 
3
+ ### General <a id="temp.arg.general">[[temp.arg.general]]</a>
4
+
5
  There are three forms of *template-argument*, corresponding to the three
6
  forms of *template-parameter*: type, non-type and template. The type and
7
  form of each *template-argument* specified in a *template-id* shall
8
  match the type and form specified for the corresponding parameter
9
  declared by the template in its *template-parameter-list*. When the
 
34
  }
35
  ```
36
 
37
  — *end example*]
38
 
39
+ The template argument list of a *template-head* is a template argument
40
+ list in which the nᵗʰ template argument has the value of the nᵗʰ
41
+ template parameter of the *template-head*. If the nᵗʰ template parameter
42
+ is a template parameter pack [[temp.variadic]], the nᵗʰ template
43
+ argument is a pack expansion whose pattern is the name of the template
44
+ parameter pack.
45
+
46
  In a *template-argument*, an ambiguity between a *type-id* and an
47
  expression is resolved to a *type-id*, regardless of the form of the
48
  corresponding *template-parameter*.[^3]
49
 
50
  [*Example 2*:
 
58
  }
59
  ```
60
 
61
  — *end example*]
62
 
63
+ [*Note 1*: Names used in a *template-argument* are subject to access
64
+ control where they appear. Because a *template-parameter* is not a class
65
+ member, no access control applies. — *end note*]
 
 
 
 
66
 
67
  [*Example 3*:
68
 
69
  ``` cpp
70
  template<class T> class X {
 
72
  };
73
 
74
  class Y {
75
  private:
76
  struct S { ... };
77
+ X<S> x; // OK, S is accessible
78
  // X<Y::S> has a static member of type Y::S
79
+ // OK, even though Y::S is private
80
  };
81
 
82
  X<Y::S> y; // error: S not accessible
83
  ```
84
 
 
111
 
112
  [*Example 5*:
113
 
114
  ``` cpp
115
  template<class T = char> class String;
116
+ String<>* p; // OK, String<char>
117
  String* q; // syntax error
118
  template<class ... Elements> class Tuple;
119
+ Tuple<>* t; // OK, Elements is empty
120
  Tuple* u; // syntax error
121
  ```
122
 
123
  — *end example*]
124
 
 
131
  ``` cpp
132
  template<class T> struct A {
133
  ~A();
134
  };
135
  void f(A<int>* p, A<int>* q) {
136
+ p->A<int>::~A(); // OK, destructor call
137
+ q->A<int>::~A<int>(); // OK, destructor call
138
  }
139
  ```
140
 
141
  — *end example*]
142
 
143
  If the use of a *template-argument* gives rise to an ill-formed
144
  construct in the instantiation of a template specialization, the program
145
  is ill-formed.
146
 
147
+ When name lookup for the component name of a *template-id* finds an
148
+ overload set, both non-template functions in the overload set and
149
+ function templates in the overload set for which the
150
+ *template-argument*s do not match the *template-parameter*s are ignored.
151
+
152
+ [*Note 2*: If none of the function templates have matching
153
+ *template-parameter*s, the program is ill-formed. — *end note*]
154
 
155
  When a *simple-template-id* does not name a function, a default
156
  *template-argument* is implicitly instantiated [[temp.inst]] when the
157
  value of that default argument is needed.
158
 
 
197
  }
198
  ```
199
 
200
  — *end example*]
201
 
202
+ [*Note 1*: A template type argument can be an incomplete type
203
+ [[term.incomplete.type]]. — *end note*]
204
 
205
  ### Template non-type arguments <a id="temp.arg.nontype">[[temp.arg.nontype]]</a>
206
 
207
  If the type `T` of a *template-parameter* [[temp.param]] contains a
208
  placeholder type [[dcl.spec.auto]] or a placeholder for a deduced class
 
324
 
325
  ### Template template arguments <a id="temp.arg.template">[[temp.arg.template]]</a>
326
 
327
  A *template-argument* for a template *template-parameter* shall be the
328
  name of a class template or an alias template, expressed as
329
+ *id-expression*. Only primary templates are considered when matching the
330
+ template template argument with the corresponding parameter; partial
 
331
  specializations are not considered even if their parameter lists match
332
  that of the template template parameter.
333
 
334
+ Any partial specializations [[temp.spec.partial]] associated with the
335
+ primary template are considered when a specialization based on the
336
+ template *template-parameter* is instantiated. If a specialization is
337
+ not reachable from the point of instantiation, and it would have been
338
+ selected had it been reachable, the program is ill-formed, no diagnostic
339
+ required.
340
 
341
  [*Example 1*:
342
 
343
  ``` cpp
344
  template<class T> class A { // primary template
 
408
  template <class T1, class T2> struct B;
409
  template <int N> struct C;
410
  template <class T1, int N> struct D;
411
  template <class T1, class T2, int N = 17> struct E;
412
 
413
+ eval<A<int>> eA; // OK, matches partial specialization of eval
414
+ eval<B<int, float>> eB; // OK, matches partial specialization of eval
415
  eval<C<17>> eC; // error: C does not match TT in partial specialization
416
  eval<D<int, 17>> eD; // error: D does not match TT in partial specialization
417
  eval<E<int, float>> eE; // error: E does not match TT in partial specialization
418
  ```
419