tmp/tmppsrjvurx/{from.md → to.md}
RENAMED
|
@@ -46,13 +46,14 @@ void g(D<int>* p, D<char>* pp, D<double>* ppp) {
|
|
| 46 |
}
|
| 47 |
```
|
| 48 |
|
| 49 |
— *end example*]
|
| 50 |
|
| 51 |
-
If
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
[*Example 2*:
|
| 56 |
|
| 57 |
``` cpp
|
| 58 |
template<class T> class X;
|
|
@@ -98,21 +99,21 @@ template<> void C<int>::g() { } // error: redefinition of C<int>::g
|
|
| 98 |
|
| 99 |
— *end example*]
|
| 100 |
|
| 101 |
However, for the purpose of determining whether an instantiated
|
| 102 |
redeclaration is valid according to [[basic.def.odr]] and
|
| 103 |
-
[[class.mem]],
|
| 104 |
-
template is considered to be a definition.
|
| 105 |
|
| 106 |
[*Example 4*:
|
| 107 |
|
| 108 |
``` cpp
|
| 109 |
template<class T, class U>
|
| 110 |
struct Outer {
|
| 111 |
template<class X, class Y> struct Inner;
|
| 112 |
template<class Y> struct Inner<T, Y>; // #1a
|
| 113 |
-
template<class Y> struct Inner<T, Y> { }; // #1b; OK
|
| 114 |
template<class Y> struct Inner<U, Y> { }; // #2
|
| 115 |
};
|
| 116 |
|
| 117 |
Outer<int, int> outer; // error at #2
|
| 118 |
```
|
|
@@ -131,19 +132,18 @@ Friendly<char> fc;
|
|
| 131 |
Friendly<float> ff; // error: produces second definition of f(U)
|
| 132 |
```
|
| 133 |
|
| 134 |
— *end example*]
|
| 135 |
|
| 136 |
-
Unless a member of a class
|
| 137 |
-
specialization
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
static data member
|
| 143 |
-
|
| 144 |
-
member to exist.
|
| 145 |
|
| 146 |
Unless a function template specialization is a declared specialization,
|
| 147 |
the function template specialization is implicitly instantiated when the
|
| 148 |
specialization is referenced in a context that requires a function
|
| 149 |
definition to exist or if the existence of the definition affects the
|
|
@@ -158,11 +158,11 @@ template is implicitly instantiated when the function is called in a
|
|
| 158 |
context that requires the value of the default argument.
|
| 159 |
|
| 160 |
[*Note 4*: An inline function that is the subject of an explicit
|
| 161 |
instantiation declaration is not a declared specialization; the intent
|
| 162 |
is that it still be implicitly instantiated when odr-used
|
| 163 |
-
[[
|
| 164 |
that no out-of-line copy of it be generated in the translation
|
| 165 |
unit. — *end note*]
|
| 166 |
|
| 167 |
[*Example 5*:
|
| 168 |
|
|
@@ -246,11 +246,11 @@ If a function template or a member function template specialization is
|
|
| 246 |
used in a way that involves overload resolution, a declaration of the
|
| 247 |
specialization is implicitly instantiated [[temp.over]].
|
| 248 |
|
| 249 |
An implementation shall not implicitly instantiate a function template,
|
| 250 |
a variable template, a member template, a non-virtual member function, a
|
| 251 |
-
member class
|
| 252 |
substatement of a constexpr if statement [[stmt.if]], unless such
|
| 253 |
instantiation is required.
|
| 254 |
|
| 255 |
[*Note 5*: The instantiation of a generic lambda does not require
|
| 256 |
instantiation of substatements of a constexpr if statement within its
|
|
@@ -258,67 +258,36 @@ instantiation of substatements of a constexpr if statement within its
|
|
| 258 |
instantiated. — *end note*]
|
| 259 |
|
| 260 |
It is unspecified whether or not an implementation implicitly
|
| 261 |
instantiates a virtual member function of a class template if the
|
| 262 |
virtual member function would not otherwise be instantiated. The use of
|
| 263 |
-
a template specialization in a default argument
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
function call causes specializations in the default argument to be
|
| 268 |
-
implicitly instantiated.
|
|
|
|
|
|
|
|
|
|
| 269 |
|
| 270 |
-
|
| 271 |
-
specializations are placed in the namespace where the template is
|
| 272 |
-
defined. Implicitly instantiated specializations for members of a class
|
| 273 |
-
template are placed in the namespace where the enclosing class template
|
| 274 |
-
is defined. Implicitly instantiated member templates are placed in the
|
| 275 |
-
namespace where the enclosing class or class template is defined.
|
| 276 |
-
|
| 277 |
-
[*Example 8*:
|
| 278 |
-
|
| 279 |
-
``` cpp
|
| 280 |
-
namespace N {
|
| 281 |
-
template<class T> class List {
|
| 282 |
-
public:
|
| 283 |
-
T* get();
|
| 284 |
-
};
|
| 285 |
-
}
|
| 286 |
-
|
| 287 |
-
template<class K, class V> class Map {
|
| 288 |
-
public:
|
| 289 |
-
N::List<V> lt;
|
| 290 |
-
V get(K);
|
| 291 |
-
};
|
| 292 |
-
|
| 293 |
-
void g(Map<const char*,int>& m) {
|
| 294 |
-
int i = m.get("Nicholas");
|
| 295 |
-
}
|
| 296 |
-
```
|
| 297 |
-
|
| 298 |
-
A call of `lt.get()` from `Map<const char*,int>::get()` would place
|
| 299 |
-
`List<int>::get()` in the namespace `N` rather than in the global
|
| 300 |
-
namespace.
|
| 301 |
-
|
| 302 |
-
— *end example*]
|
| 303 |
-
|
| 304 |
-
If a function template `f` is called in a way that requires a default
|
| 305 |
argument to be used, the dependent names are looked up, the semantics
|
| 306 |
constraints are checked, and the instantiation of any template used in
|
| 307 |
the default argument is done as if the default argument had been an
|
| 308 |
initializer used in a function template specialization with the same
|
| 309 |
scope, the same template parameters and the same access as that of the
|
| 310 |
function template `f` used at that point, except that the scope in which
|
| 311 |
-
a closure type is declared [[expr.prim.lambda.closure]]
|
| 312 |
-
its associated namespaces
|
| 313 |
definition for the default argument. This analysis is called *default
|
| 314 |
argument instantiation*. The instantiated default argument is then used
|
| 315 |
as the argument of `f`.
|
| 316 |
|
| 317 |
Each default argument is instantiated independently.
|
| 318 |
|
| 319 |
-
[*Example
|
| 320 |
|
| 321 |
``` cpp
|
| 322 |
template<class T> void f(T x, T y = ydef(T()), T z = zdef(T()));
|
| 323 |
|
| 324 |
class A { };
|
|
@@ -349,11 +318,11 @@ template specialization. — *end note*]
|
|
| 349 |
There is an *implementation-defined* quantity that specifies the limit
|
| 350 |
on the total depth of recursive instantiations [[implimits]], which
|
| 351 |
could involve more than one template. The result of an infinite
|
| 352 |
recursion in instantiation is undefined.
|
| 353 |
|
| 354 |
-
[*Example
|
| 355 |
|
| 356 |
``` cpp
|
| 357 |
template<class T> class X {
|
| 358 |
X<T>* p; // OK
|
| 359 |
X<T*> a; // implicit generation of X<T> requires
|
|
@@ -375,11 +344,11 @@ declarations.
|
|
| 375 |
|
| 376 |
[*Note 7*: The satisfaction of constraints is determined during
|
| 377 |
template argument deduction [[temp.deduct]] and overload resolution
|
| 378 |
[[over.match]]. — *end note*]
|
| 379 |
|
| 380 |
-
[*Example
|
| 381 |
|
| 382 |
``` cpp
|
| 383 |
template<typename T> concept C = sizeof(T) > 2;
|
| 384 |
template<typename T> concept D = C<T> && sizeof(T) > 4;
|
| 385 |
|
|
@@ -397,11 +366,11 @@ specialization. Their constraints are not satisfied, and they suppress
|
|
| 397 |
the implicit declaration of a default constructor for `S<char>`
|
| 398 |
[[class.default.ctor]], so there is no viable constructor for `s1`.
|
| 399 |
|
| 400 |
— *end example*]
|
| 401 |
|
| 402 |
-
[*Example
|
| 403 |
|
| 404 |
``` cpp
|
| 405 |
template<typename T> struct S1 {
|
| 406 |
template<typename U>
|
| 407 |
requires false
|
|
|
|
| 46 |
}
|
| 47 |
```
|
| 48 |
|
| 49 |
— *end example*]
|
| 50 |
|
| 51 |
+
If the template selected for the specialization
|
| 52 |
+
[[temp.spec.partial.match]] has been declared, but not defined, at the
|
| 53 |
+
point of instantiation [[temp.point]], the instantiation yields an
|
| 54 |
+
incomplete class type [[term.incomplete.type]].
|
| 55 |
|
| 56 |
[*Example 2*:
|
| 57 |
|
| 58 |
``` cpp
|
| 59 |
template<class T> class X;
|
|
|
|
| 99 |
|
| 100 |
— *end example*]
|
| 101 |
|
| 102 |
However, for the purpose of determining whether an instantiated
|
| 103 |
redeclaration is valid according to [[basic.def.odr]] and
|
| 104 |
+
[[class.mem]], an instantiated declaration that corresponds to a
|
| 105 |
+
definition in the template is considered to be a definition.
|
| 106 |
|
| 107 |
[*Example 4*:
|
| 108 |
|
| 109 |
``` cpp
|
| 110 |
template<class T, class U>
|
| 111 |
struct Outer {
|
| 112 |
template<class X, class Y> struct Inner;
|
| 113 |
template<class Y> struct Inner<T, Y>; // #1a
|
| 114 |
+
template<class Y> struct Inner<T, Y> { }; // #1b; OK, valid redeclaration of #1a
|
| 115 |
template<class Y> struct Inner<U, Y> { }; // #2
|
| 116 |
};
|
| 117 |
|
| 118 |
Outer<int, int> outer; // error at #2
|
| 119 |
```
|
|
|
|
| 132 |
Friendly<float> ff; // error: produces second definition of f(U)
|
| 133 |
```
|
| 134 |
|
| 135 |
— *end example*]
|
| 136 |
|
| 137 |
+
Unless a member of a templated class is a declared specialization, the
|
| 138 |
+
specialization of the member is implicitly instantiated when the
|
| 139 |
+
specialization is referenced in a context that requires the member
|
| 140 |
+
definition to exist or if the existence of the definition of the member
|
| 141 |
+
affects the semantics of the program; in particular, the initialization
|
| 142 |
+
(and any associated side effects) of a static data member does not occur
|
| 143 |
+
unless the static data member is itself used in a way that requires the
|
| 144 |
+
definition of the static data member to exist.
|
|
|
|
| 145 |
|
| 146 |
Unless a function template specialization is a declared specialization,
|
| 147 |
the function template specialization is implicitly instantiated when the
|
| 148 |
specialization is referenced in a context that requires a function
|
| 149 |
definition to exist or if the existence of the definition affects the
|
|
|
|
| 158 |
context that requires the value of the default argument.
|
| 159 |
|
| 160 |
[*Note 4*: An inline function that is the subject of an explicit
|
| 161 |
instantiation declaration is not a declared specialization; the intent
|
| 162 |
is that it still be implicitly instantiated when odr-used
|
| 163 |
+
[[term.odr.use]] so that the body can be considered for inlining, but
|
| 164 |
that no out-of-line copy of it be generated in the translation
|
| 165 |
unit. — *end note*]
|
| 166 |
|
| 167 |
[*Example 5*:
|
| 168 |
|
|
|
|
| 246 |
used in a way that involves overload resolution, a declaration of the
|
| 247 |
specialization is implicitly instantiated [[temp.over]].
|
| 248 |
|
| 249 |
An implementation shall not implicitly instantiate a function template,
|
| 250 |
a variable template, a member template, a non-virtual member function, a
|
| 251 |
+
member class or static data member of a templated class, or a
|
| 252 |
substatement of a constexpr if statement [[stmt.if]], unless such
|
| 253 |
instantiation is required.
|
| 254 |
|
| 255 |
[*Note 5*: The instantiation of a generic lambda does not require
|
| 256 |
instantiation of substatements of a constexpr if statement within its
|
|
|
|
| 258 |
instantiated. — *end note*]
|
| 259 |
|
| 260 |
It is unspecified whether or not an implementation implicitly
|
| 261 |
instantiates a virtual member function of a class template if the
|
| 262 |
virtual member function would not otherwise be instantiated. The use of
|
| 263 |
+
a template specialization in a default argument or default member
|
| 264 |
+
initializer shall not cause the template to be implicitly instantiated
|
| 265 |
+
except where needed to determine the correctness of the default argument
|
| 266 |
+
or default member initializer. The use of a default argument in a
|
| 267 |
function call causes specializations in the default argument to be
|
| 268 |
+
implicitly instantiated. Similarly, the use of a default member
|
| 269 |
+
initializer in a constructor definition or an aggregate initialization
|
| 270 |
+
causes specializations in the default member initializer to be
|
| 271 |
+
instantiated.
|
| 272 |
|
| 273 |
+
If a templated function `f` is called in a way that requires a default
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
argument to be used, the dependent names are looked up, the semantics
|
| 275 |
constraints are checked, and the instantiation of any template used in
|
| 276 |
the default argument is done as if the default argument had been an
|
| 277 |
initializer used in a function template specialization with the same
|
| 278 |
scope, the same template parameters and the same access as that of the
|
| 279 |
function template `f` used at that point, except that the scope in which
|
| 280 |
+
a closure type is declared [[expr.prim.lambda.closure]] — and therefore
|
| 281 |
+
its associated namespaces — remain as determined from the context of the
|
| 282 |
definition for the default argument. This analysis is called *default
|
| 283 |
argument instantiation*. The instantiated default argument is then used
|
| 284 |
as the argument of `f`.
|
| 285 |
|
| 286 |
Each default argument is instantiated independently.
|
| 287 |
|
| 288 |
+
[*Example 8*:
|
| 289 |
|
| 290 |
``` cpp
|
| 291 |
template<class T> void f(T x, T y = ydef(T()), T z = zdef(T()));
|
| 292 |
|
| 293 |
class A { };
|
|
|
|
| 318 |
There is an *implementation-defined* quantity that specifies the limit
|
| 319 |
on the total depth of recursive instantiations [[implimits]], which
|
| 320 |
could involve more than one template. The result of an infinite
|
| 321 |
recursion in instantiation is undefined.
|
| 322 |
|
| 323 |
+
[*Example 9*:
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
template<class T> class X {
|
| 327 |
X<T>* p; // OK
|
| 328 |
X<T*> a; // implicit generation of X<T> requires
|
|
|
|
| 344 |
|
| 345 |
[*Note 7*: The satisfaction of constraints is determined during
|
| 346 |
template argument deduction [[temp.deduct]] and overload resolution
|
| 347 |
[[over.match]]. — *end note*]
|
| 348 |
|
| 349 |
+
[*Example 10*:
|
| 350 |
|
| 351 |
``` cpp
|
| 352 |
template<typename T> concept C = sizeof(T) > 2;
|
| 353 |
template<typename T> concept D = C<T> && sizeof(T) > 4;
|
| 354 |
|
|
|
|
| 366 |
the implicit declaration of a default constructor for `S<char>`
|
| 367 |
[[class.default.ctor]], so there is no viable constructor for `s1`.
|
| 368 |
|
| 369 |
— *end example*]
|
| 370 |
|
| 371 |
+
[*Example 11*:
|
| 372 |
|
| 373 |
``` cpp
|
| 374 |
template<typename T> struct S1 {
|
| 375 |
template<typename U>
|
| 376 |
requires false
|