From Jason Turner

[temp.explicit]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1worqr21/{from.md → to.md} +76 -49
tmp/tmp1worqr21/{from.md → to.md} RENAMED
@@ -22,39 +22,49 @@ instantiation declaration begins with the `extern` keyword.
22
  If the explicit instantiation is for a class or member class, the
23
  *elaborated-type-specifier* in the *declaration* shall include a
24
  *simple-template-id*. If the explicit instantiation is for a function or
25
  member function, the *unqualified-id* in the *declaration* shall be
26
  either a *template-id* or, where all template arguments can be deduced,
27
- a *template-name* or *operator-function-id*. The declaration may declare
28
- a *qualified-id*, in which case the *unqualified-id* of the
29
- *qualified-id* must be a *template-id*. If the explicit instantiation is
30
- for a member function, a member class or a static data member of a class
31
- template specialization, the name of the class template specialization
32
- in the *qualified-id* for the member name shall be a
33
- *simple-template-id*. If the explicit instantiation is for a variable,
34
- the *unqualified-id* in the declaration shall be a *template-id*. An
35
- explicit instantiation shall appear in an enclosing namespace of its
36
- template. If the name declared in the explicit instantiation is an
37
- unqualified name, the explicit instantiation shall appear in the
38
- namespace where its template is declared or, if that namespace is
39
- inline ([[namespace.def]]), any namespace from its enclosing namespace
40
- set. Regarding qualified names in declarators, see  [[dcl.meaning]].
 
 
 
 
 
 
 
 
41
 
42
  ``` cpp
43
  template<class T> class Array { void mf(); };
44
  template class Array<char>;
45
  template void Array<int>::mf();
46
 
47
- template<class T> void sort(Array<T>& v) { /* ... */ }
48
  template void sort(Array<char>&); // argument is deduced here
49
 
50
  namespace N {
51
  template<class T> void f(T&) { }
52
  }
53
  template void N::f<int>(int&);
54
  ```
55
 
 
 
56
  A declaration of a function template, a variable template, a member
57
  function or static data member of a class template, or a member function
58
  template of a class or class template shall precede an explicit
59
  instantiation of that entity. A definition of a class template, a member
60
  class of a class template, or a member class template of a class or
@@ -78,92 +88,109 @@ template specialization is placed in the namespace in which the template
78
  is defined. An explicit instantiation for a member of a class template
79
  is placed in the namespace where the enclosing class template is
80
  defined. An explicit instantiation for a member template is placed in
81
  the namespace where the enclosing class or class template is defined.
82
 
 
 
83
  ``` cpp
84
  namespace N {
85
  template<class T> class Y { void mf() { } };
86
  }
87
 
88
- template class Y<int>; // error: class template Y not visible
89
- // in the global namespace
90
 
91
  using N::Y;
92
- template class Y<int>; // error: explicit instantiation outside of the
93
- // namespace of the template
94
 
95
  template class N::Y<char*>; // OK: explicit instantiation in namespace N
96
- template void N::Y<double>::mf(); // OK: explicit instantiation
97
- // in namespace N
98
  ```
99
 
 
 
100
  A trailing *template-argument* can be left unspecified in an explicit
101
  instantiation of a function template specialization or of a member
102
  function template specialization provided it can be deduced from the
103
  type of a function parameter ([[temp.deduct]]).
104
 
 
 
105
  ``` cpp
106
- template<class T> class Array { /* ... */ };
107
- template<class T> void sort(Array<T>& v) { /* ... */ }
108
 
109
- // instantiate sort(Array<int>&) - template-argument deduced
110
  template void sort<>(Array<int>&);
111
  ```
112
 
 
 
113
  An explicit instantiation that names a class template specialization is
114
  also an explicit instantiation of the same kind (declaration or
115
  definition) of each of its members (not including members inherited from
116
  base classes and members that are templates) that has not been
117
  previously explicitly specialized in the translation unit containing the
118
- explicit instantiation, except as described below. In addition, it will
119
- typically be an explicit instantiation of certain
120
- implementation-dependent data about the class.
 
121
 
122
  An explicit instantiation definition that names a class template
123
  specialization explicitly instantiates the class template specialization
124
  and is an explicit instantiation definition of only those members that
125
  have been defined at the point of instantiation.
126
 
127
- Except for inline functions, declarations with types deduced from their
128
- initializer or return value ([[dcl.spec.auto]]), `const` variables of
129
- literal types, variables of reference types, and class template
130
- specializations, explicit instantiation declarations have the effect of
131
- suppressing the implicit instantiation of the entity to which they
132
- refer. The intent is that an inline function that is the subject of an
133
- explicit instantiation declaration will still be implicitly instantiated
134
- when odr-used ([[basic.def.odr]]) so that the body can be considered
135
- for inlining, but that no out-of-line copy of the inline function would
136
- be generated in the translation unit.
 
 
137
 
138
  If an entity is the subject of both an explicit instantiation
139
  declaration and an explicit instantiation definition in the same
140
  translation unit, the definition shall follow the declaration. An entity
141
  that is the subject of an explicit instantiation declaration and that is
142
  also used in a way that would otherwise cause an implicit
143
  instantiation ([[temp.inst]]) in the translation unit shall be the
144
  subject of an explicit instantiation definition somewhere in the
145
  program; otherwise the program is ill-formed, no diagnostic required.
146
- This rule does apply to inline functions even though an explicit
147
- instantiation declaration of such an entity has no other normative
148
- effect. This is needed to ensure that if the address of an inline
149
- function is taken in a translation unit in which the implementation
150
- chose to suppress the out-of-line body, another translation unit will
151
- supply the body. An explicit instantiation declaration shall not name a
152
- specialization of a template with internal linkage.
 
 
 
153
 
154
  The usual access checking rules do not apply to names used to specify
155
- explicit instantiations. In particular, the template arguments and names
156
- used in the function declarator (including parameter types, return types
157
- and exception specifications) may be private types or objects which
158
- would normally not be accessible and the template may be a member
159
- template or member function which would not normally be accessible.
 
 
160
 
161
  An explicit instantiation does not constitute a use of a default
162
  argument, so default argument instantiation is not done.
163
 
 
 
164
  ``` cpp
165
  char* p = 0;
166
  template<class T> T g(T x = &p) { return x; }
167
  template int g<int>(int); // OK even though &p isn't an int.
168
  ```
169
 
 
 
 
22
  If the explicit instantiation is for a class or member class, the
23
  *elaborated-type-specifier* in the *declaration* shall include a
24
  *simple-template-id*. If the explicit instantiation is for a function or
25
  member function, the *unqualified-id* in the *declaration* shall be
26
  either a *template-id* or, where all template arguments can be deduced,
27
+ a *template-name* or *operator-function-id*.
28
+
29
+ [*Note 1*: The declaration may declare a *qualified-id*, in which case
30
+ the *unqualified-id* of the *qualified-id* must be a
31
+ *template-id*. *end note*]
32
+
33
+ If the explicit instantiation is for a member function, a member class
34
+ or a static data member of a class template specialization, the name of
35
+ the class template specialization in the *qualified-id* for the member
36
+ name shall be a *simple-template-id*. If the explicit instantiation is
37
+ for a variable, the *unqualified-id* in the declaration shall be a
38
+ *template-id*. An explicit instantiation shall appear in an enclosing
39
+ namespace of its template. If the name declared in the explicit
40
+ instantiation is an unqualified name, the explicit instantiation shall
41
+ appear in the namespace where its template is declared or, if that
42
+ namespace is inline ([[namespace.def]]), any namespace from its
43
+ enclosing namespace set.
44
+
45
+ [*Note 2*: Regarding qualified names in declarators, see 
46
+ [[dcl.meaning]]. — *end note*]
47
+
48
+ [*Example 1*:
49
 
50
  ``` cpp
51
  template<class T> class Array { void mf(); };
52
  template class Array<char>;
53
  template void Array<int>::mf();
54
 
55
+ template<class T> void sort(Array<T>& v) { ... }
56
  template void sort(Array<char>&); // argument is deduced here
57
 
58
  namespace N {
59
  template<class T> void f(T&) { }
60
  }
61
  template void N::f<int>(int&);
62
  ```
63
 
64
+ — *end example*]
65
+
66
  A declaration of a function template, a variable template, a member
67
  function or static data member of a class template, or a member function
68
  template of a class or class template shall precede an explicit
69
  instantiation of that entity. A definition of a class template, a member
70
  class of a class template, or a member class template of a class or
 
88
  is defined. An explicit instantiation for a member of a class template
89
  is placed in the namespace where the enclosing class template is
90
  defined. An explicit instantiation for a member template is placed in
91
  the namespace where the enclosing class or class template is defined.
92
 
93
+ [*Example 2*:
94
+
95
  ``` cpp
96
  namespace N {
97
  template<class T> class Y { void mf() { } };
98
  }
99
 
100
+ template class Y<int>; // error: class template Y not visible in the global namespace
 
101
 
102
  using N::Y;
103
+ template class Y<int>; // error: explicit instantiation outside of the namespace of the template
 
104
 
105
  template class N::Y<char*>; // OK: explicit instantiation in namespace N
106
+ template void N::Y<double>::mf(); // OK: explicit instantiation in namespace N
 
107
  ```
108
 
109
+ — *end example*]
110
+
111
  A trailing *template-argument* can be left unspecified in an explicit
112
  instantiation of a function template specialization or of a member
113
  function template specialization provided it can be deduced from the
114
  type of a function parameter ([[temp.deduct]]).
115
 
116
+ [*Example 3*:
117
+
118
  ``` cpp
119
+ template<class T> class Array { ... };
120
+ template<class T> void sort(Array<T>& v) { ... }
121
 
122
+ // instantiate sort(Array<int>&) -- template-argument deduced
123
  template void sort<>(Array<int>&);
124
  ```
125
 
126
+ — *end example*]
127
+
128
  An explicit instantiation that names a class template specialization is
129
  also an explicit instantiation of the same kind (declaration or
130
  definition) of each of its members (not including members inherited from
131
  base classes and members that are templates) that has not been
132
  previously explicitly specialized in the translation unit containing the
133
+ explicit instantiation, except as described below.
134
+
135
+ [*Note 3*: In addition, it will typically be an explicit instantiation
136
+ of certain implementation-dependent data about the class. — *end note*]
137
 
138
  An explicit instantiation definition that names a class template
139
  specialization explicitly instantiates the class template specialization
140
  and is an explicit instantiation definition of only those members that
141
  have been defined at the point of instantiation.
142
 
143
+ Except for inline functions and variables, declarations with types
144
+ deduced from their initializer or return value ([[dcl.spec.auto]]),
145
+ `const` variables of literal types, variables of reference types, and
146
+ class template specializations, explicit instantiation declarations have
147
+ the effect of suppressing the implicit instantiation of the entity to
148
+ which they refer.
149
+
150
+ [*Note 4*: The intent is that an inline function that is the subject of
151
+ an explicit instantiation declaration will still be implicitly
152
+ instantiated when odr-used ([[basic.def.odr]]) so that the body can be
153
+ considered for inlining, but that no out-of-line copy of the inline
154
+ function would be generated in the translation unit. — *end note*]
155
 
156
  If an entity is the subject of both an explicit instantiation
157
  declaration and an explicit instantiation definition in the same
158
  translation unit, the definition shall follow the declaration. An entity
159
  that is the subject of an explicit instantiation declaration and that is
160
  also used in a way that would otherwise cause an implicit
161
  instantiation ([[temp.inst]]) in the translation unit shall be the
162
  subject of an explicit instantiation definition somewhere in the
163
  program; otherwise the program is ill-formed, no diagnostic required.
164
+
165
+ [*Note 5*: This rule does apply to inline functions even though an
166
+ explicit instantiation declaration of such an entity has no other
167
+ normative effect. This is needed to ensure that if the address of an
168
+ inline function is taken in a translation unit in which the
169
+ implementation chose to suppress the out-of-line body, another
170
+ translation unit will supply the body. — *end note*]
171
+
172
+ An explicit instantiation declaration shall not name a specialization of
173
+ a template with internal linkage.
174
 
175
  The usual access checking rules do not apply to names used to specify
176
+ explicit instantiations.
177
+
178
+ [*Note 6*: In particular, the template arguments and names used in the
179
+ function declarator (including parameter types, return types and
180
+ exception specifications) may be private types or objects which would
181
+ normally not be accessible and the template may be a member template or
182
+ member function which would not normally be accessible. — *end note*]
183
 
184
  An explicit instantiation does not constitute a use of a default
185
  argument, so default argument instantiation is not done.
186
 
187
+ [*Example 4*:
188
+
189
  ``` cpp
190
  char* p = 0;
191
  template<class T> T g(T x = &p) { return x; }
192
  template int g<int>(int); // OK even though &p isn't an int.
193
  ```
194
 
195
+ — *end example*]
196
+