From Jason Turner

[temp.explicit]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpifmpwro7/{from.md → to.md} +84 -50
tmp/tmpifmpwro7/{from.md → to.md} RENAMED
@@ -2,47 +2,55 @@
2
 
3
  A class, function, variable, or member template specialization can be
4
  explicitly instantiated from its template. A member function, member
5
  class or static data member of a class template can be explicitly
6
  instantiated from the member definition associated with its class
7
- template. An explicit instantiation of a function template or member
8
- function of a class template shall not use the `inline` or `constexpr`
9
- specifiers.
10
 
11
  The syntax for explicit instantiation is:
12
 
13
  ``` bnf
14
  explicit-instantiation:
15
- 'extern'ₒₚₜ 'template' declaration
16
  ```
17
 
18
  There are two forms of explicit instantiation: an explicit instantiation
19
  definition and an explicit instantiation declaration. An explicit
20
  instantiation declaration begins with the `extern` keyword.
21
 
 
 
 
 
 
 
 
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*:
@@ -70,17 +78,50 @@ 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
71
  class template shall precede an explicit instantiation of that entity
72
  unless the explicit instantiation is preceded by an explicit
73
  specialization of the entity with the same template arguments. If the
74
  *declaration* of the explicit instantiation names an implicitly-declared
75
- special member function (Clause  [[special]]), the program is
76
- ill-formed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  For a given set of template arguments, if an explicit instantiation of a
79
  template appears after a declaration of an explicit specialization for
80
  that template, the explicit instantiation has no effect. Otherwise, for
81
- an explicit instantiation definition the definition of a function
82
  template, a variable template, a member function template, or a member
83
  function or static data member of a class template shall be present in
84
  every translation unit in which it is explicitly instantiated.
85
 
86
  An explicit instantiation of a class, function template, or variable
@@ -88,11 +129,11 @@ template specialization is placed in the namespace in which the template
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
  }
@@ -109,13 +150,13 @@ template void N::Y<double>::mf(); // OK: explicit instantiation in namespa
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
 
@@ -123,70 +164,63 @@ template<class T> void sort(Array<T>& v) { ... }
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.
 
2
 
3
  A class, function, variable, or member template specialization can be
4
  explicitly instantiated from its template. A member function, member
5
  class or static data member of a class template can be explicitly
6
  instantiated from the member definition associated with its class
7
+ template.
 
 
8
 
9
  The syntax for explicit instantiation is:
10
 
11
  ``` bnf
12
  explicit-instantiation:
13
+ externₒₚₜ template declaration
14
  ```
15
 
16
  There are two forms of explicit instantiation: an explicit instantiation
17
  definition and an explicit instantiation declaration. An explicit
18
  instantiation declaration begins with the `extern` keyword.
19
 
20
+ An explicit instantiation shall not use a *storage-class-specifier*
21
+ [[dcl.stc]] other than `thread_local`. An explicit instantiation of a
22
+ function template, member function of a class template, or variable
23
+ template shall not use the `inline`, `constexpr`, or `consteval`
24
+ specifiers. No *attribute-specifier-seq* [[dcl.attr.grammar]] shall
25
+ appertain to an explicit instantiation.
26
+
27
  If the explicit instantiation is for a class or member class, the
28
  *elaborated-type-specifier* in the *declaration* shall include a
29
+ *simple-template-id*; otherwise, the *declaration* shall be a
30
+ *simple-declaration* whose *init-declarator-list* comprises a single
31
+ *init-declarator* that does not have an *initializer*. If the explicit
32
+ instantiation is for a function or member function, the *unqualified-id*
33
+ in the *declarator* shall be either a *template-id* or, where all
34
+ template arguments can be deduced, a *template-name* or
35
+ *operator-function-id*.
36
 
37
  [*Note 1*: The declaration may declare a *qualified-id*, in which case
38
  the *unqualified-id* of the *qualified-id* must be a
39
  *template-id*. — *end note*]
40
 
41
  If the explicit instantiation is for a member function, a member class
42
  or a static data member of a class template specialization, the name of
43
  the class template specialization in the *qualified-id* for the member
44
  name shall be a *simple-template-id*. If the explicit instantiation is
45
+ for a variable template specialization, the *unqualified-id* in the
46
+ *declarator* shall be a *simple-template-id*. An explicit instantiation
47
+ shall appear in an enclosing namespace of its template. If the name
48
+ declared in the explicit instantiation is an unqualified name, the
49
+ explicit instantiation shall appear in the namespace where its template
50
+ is declared or, if that namespace is inline [[namespace.def]], any
51
+ namespace from its enclosing namespace set.
52
 
53
  [*Note 2*: Regarding qualified names in declarators, see 
54
  [[dcl.meaning]]. — *end note*]
55
 
56
  [*Example 1*:
 
78
  class of a class template, or a member class template of a class or
79
  class template shall precede an explicit instantiation of that entity
80
  unless the explicit instantiation is preceded by an explicit
81
  specialization of the entity with the same template arguments. If the
82
  *declaration* of the explicit instantiation names an implicitly-declared
83
+ special member function [[special]], the program is ill-formed.
84
+
85
+ The *declaration* in an *explicit-instantiation* and the *declaration*
86
+ produced by the corresponding substitution into the templated function,
87
+ variable, or class are two declarations of the same entity.
88
+
89
+ [*Note 3*:
90
+
91
+ These declarations are required to have matching types as specified in 
92
+ [[basic.link]], except as specified in  [[except.spec]].
93
+
94
+ [*Example 2*:
95
+
96
+ ``` cpp
97
+ template<typename T> T var = {};
98
+ template float var<float>; // OK, instantiated variable has type float
99
+ template int var<int[16]>[]; // OK, absence of major array bound is permitted
100
+ template int *var<int>; // error: instantiated variable has type int
101
+
102
+ template<typename T> auto av = T();
103
+ template int av<int>; // OK, variable with type int can be redeclared with type auto
104
+
105
+ template<typename T> auto f() {}
106
+ template void f<int>(); // error: function with deduced return type
107
+ // redeclared with non-deduced return type[dcl.spec.auto]
108
+ ```
109
+
110
+ — *end example*]
111
+
112
+ — *end note*]
113
+
114
+ Despite its syntactic form, the *declaration* in an
115
+ *explicit-instantiation* for a variable is not itself a definition and
116
+ does not conflict with the definition instantiated by an explicit
117
+ instantiation definition for that variable.
118
 
119
  For a given set of template arguments, if an explicit instantiation of a
120
  template appears after a declaration of an explicit specialization for
121
  that template, the explicit instantiation has no effect. Otherwise, for
122
+ an explicit instantiation definition, the definition of a function
123
  template, a variable template, a member function template, or a member
124
  function or static data member of a class template shall be present in
125
  every translation unit in which it is explicitly instantiated.
126
 
127
  An explicit instantiation of a class, function template, or variable
 
129
  is defined. An explicit instantiation for a member of a class template
130
  is placed in the namespace where the enclosing class template is
131
  defined. An explicit instantiation for a member template is placed in
132
  the namespace where the enclosing class or class template is defined.
133
 
134
+ [*Example 3*:
135
 
136
  ``` cpp
137
  namespace N {
138
  template<class T> class Y { void mf() { } };
139
  }
 
150
  — *end example*]
151
 
152
  A trailing *template-argument* can be left unspecified in an explicit
153
  instantiation of a function template specialization or of a member
154
  function template specialization provided it can be deduced from the
155
+ type of a function parameter [[temp.deduct]].
156
 
157
+ [*Example 4*:
158
 
159
  ``` cpp
160
  template<class T> class Array { ... };
161
  template<class T> void sort(Array<T>& v) { ... }
162
 
 
164
  template void sort<>(Array<int>&);
165
  ```
166
 
167
  — *end example*]
168
 
169
+ [*Note 4*: An explicit instantiation of a constrained template is
170
+ required to satisfy that template’s associated constraints
171
+ [[temp.constr.decl]]. The satisfaction of constraints is determined when
172
+ forming the template name of an explicit instantiation in which all
173
+ template arguments are specified [[temp.names]], or, for explicit
174
+ instantiations of function templates, during template argument deduction
175
+ [[temp.deduct.decl]] when one or more trailing template arguments are
176
+ left unspecified. — *end note*]
177
+
178
  An explicit instantiation that names a class template specialization is
179
  also an explicit instantiation of the same kind (declaration or
180
  definition) of each of its members (not including members inherited from
181
  base classes and members that are templates) that has not been
182
  previously explicitly specialized in the translation unit containing the
183
+ explicit instantiation, provided that the associated constraints, if
184
+ any, of that member are satisfied by the template arguments of the
185
+ explicit instantiation ([[temp.constr.decl]], [[temp.constr.constr]]),
186
+ except as described below.
187
 
188
+ [*Note 5*: In addition, it will typically be an explicit instantiation
189
  of certain implementation-dependent data about the class. — *end note*]
190
 
191
  An explicit instantiation definition that names a class template
192
  specialization explicitly instantiates the class template specialization
193
  and is an explicit instantiation definition of only those members that
194
  have been defined at the point of instantiation.
195
 
196
+ An explicit instantiation of a prospective destructor [[class.dtor]]
197
+ shall name the selected destructor of the class.
 
 
 
 
 
 
 
 
 
 
198
 
199
  If an entity is the subject of both an explicit instantiation
200
  declaration and an explicit instantiation definition in the same
201
  translation unit, the definition shall follow the declaration. An entity
202
  that is the subject of an explicit instantiation declaration and that is
203
+ also used in a way that would otherwise cause an implicit instantiation
204
+ [[temp.inst]] in the translation unit shall be the subject of an
205
+ explicit instantiation definition somewhere in the program; otherwise
206
+ the program is ill-formed, no diagnostic required.
207
 
208
+ [*Note 6*: This rule does apply to inline functions even though an
209
  explicit instantiation declaration of such an entity has no other
210
  normative effect. This is needed to ensure that if the address of an
211
  inline function is taken in a translation unit in which the
212
  implementation chose to suppress the out-of-line body, another
213
  translation unit will supply the body. — *end note*]
214
 
215
  An explicit instantiation declaration shall not name a specialization of
216
  a template with internal linkage.
217
 
 
 
 
 
 
 
 
 
 
218
  An explicit instantiation does not constitute a use of a default
219
  argument, so default argument instantiation is not done.
220
 
221
+ [*Example 5*:
222
 
223
  ``` cpp
224
  char* p = 0;
225
  template<class T> T g(T x = &p) { return x; }
226
  template int g<int>(int); // OK even though &p isn't an int.