- tmp/tmp8jaw_fj8/{from.md → to.md} +99 -180
tmp/tmp8jaw_fj8/{from.md → to.md}
RENAMED
|
@@ -1,39 +1,46 @@
|
|
| 1 |
### Dependent names <a id="temp.dep">[[temp.dep]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
Inside a template, some constructs have semantics which may differ from
|
| 4 |
one instantiation to another. Such a construct *depends* on the template
|
| 5 |
parameters. In particular, types and expressions may depend on the type
|
| 6 |
and/or value of template parameters (as determined by the template
|
| 7 |
arguments) and this determines the context for name lookup for certain
|
| 8 |
names. An expression may be *type-dependent* (that is, its type may
|
| 9 |
depend on a template parameter) or *value-dependent* (that is, its value
|
| 10 |
when evaluated as a constant expression [[expr.const]] may depend on a
|
| 11 |
-
template parameter) as described
|
| 12 |
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
``` bnf
|
| 16 |
postfix-expression '(' expression-listₒₚₜ ')'
|
| 17 |
```
|
| 18 |
|
| 19 |
-
where the *postfix-expression* is an *unqualified-id*
|
| 20 |
-
*unqualified-id* denotes a *dependent name* if
|
| 21 |
|
| 22 |
- any of the expressions in the *expression-list* is a pack expansion
|
| 23 |
-
[[temp.variadic]],
|
| 24 |
- any of the expressions or *braced-init-list*s in the *expression-list*
|
| 25 |
is type-dependent [[temp.dep.expr]], or
|
| 26 |
- the *unqualified-id* is a *template-id* in which any of the template
|
| 27 |
arguments depends on a template parameter.
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
[[temp.dep.candidate]]. — *end note*]
|
| 36 |
|
| 37 |
[*Example 1*:
|
| 38 |
|
| 39 |
``` cpp
|
|
@@ -49,88 +56,30 @@ template<class T> struct X : B<T> {
|
|
| 49 |
The base class name `B<T>`, the type name `T::A`, the names `B<T>::i`
|
| 50 |
and `pb->j` explicitly depend on the *template-parameter*.
|
| 51 |
|
| 52 |
— *end example*]
|
| 53 |
|
| 54 |
-
In the definition of a class or class template, the scope of a dependent
|
| 55 |
-
base class [[temp.dep.type]] is not examined during unqualified name
|
| 56 |
-
lookup either at the point of definition of the class template or member
|
| 57 |
-
or during an instantiation of the class template or member.
|
| 58 |
-
|
| 59 |
-
[*Example 2*:
|
| 60 |
-
|
| 61 |
-
``` cpp
|
| 62 |
-
typedef double A;
|
| 63 |
-
template<class T> class B {
|
| 64 |
-
typedef int A;
|
| 65 |
-
};
|
| 66 |
-
template<class T> struct X : B<T> {
|
| 67 |
-
A a; // a has type double
|
| 68 |
-
};
|
| 69 |
-
```
|
| 70 |
-
|
| 71 |
-
The type name `A` in the definition of `X<T>` binds to the typedef name
|
| 72 |
-
defined in the global namespace scope, not to the typedef name defined
|
| 73 |
-
in the base class `B<T>`.
|
| 74 |
-
|
| 75 |
-
— *end example*]
|
| 76 |
-
|
| 77 |
-
[*Example 3*:
|
| 78 |
-
|
| 79 |
-
``` cpp
|
| 80 |
-
struct A {
|
| 81 |
-
struct B { ... };
|
| 82 |
-
int a;
|
| 83 |
-
int Y;
|
| 84 |
-
};
|
| 85 |
-
|
| 86 |
-
int a;
|
| 87 |
-
|
| 88 |
-
template<class T> struct Y : T {
|
| 89 |
-
struct B { ... };
|
| 90 |
-
B b; // The B defined in Y
|
| 91 |
-
void f(int i) { a = i; } // ::a
|
| 92 |
-
Y* p; // Y<T>
|
| 93 |
-
};
|
| 94 |
-
|
| 95 |
-
Y<A> ya;
|
| 96 |
-
```
|
| 97 |
-
|
| 98 |
-
The members `A::B`, `A::a`, and `A::Y` of the template argument `A` do
|
| 99 |
-
not affect the binding of names in `Y<A>`.
|
| 100 |
-
|
| 101 |
-
— *end example*]
|
| 102 |
-
|
| 103 |
#### Dependent types <a id="temp.dep.type">[[temp.dep.type]]</a>
|
| 104 |
|
| 105 |
-
A name refers to the *current instantiation* if it is
|
| 106 |
|
| 107 |
- in the definition of a class template, a nested class of a class
|
| 108 |
template, a member of a class template, or a member of a nested class
|
| 109 |
of a class template, the injected-class-name [[class.pre]] of the
|
| 110 |
class template or nested class,
|
| 111 |
- in the definition of a primary class template or a member of a primary
|
| 112 |
class template, the name of the class template followed by the
|
| 113 |
-
template argument list of
|
| 114 |
-
|
| 115 |
- in the definition of a nested class of a class template, the name of
|
| 116 |
the nested class referenced as a member of the current instantiation,
|
| 117 |
or
|
| 118 |
-
- in the definition of a partial specialization or a
|
| 119 |
-
|
| 120 |
-
template
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
pack expansion [[temp.variadic]] whose pattern is the name of the
|
| 124 |
-
template parameter pack.
|
| 125 |
-
|
| 126 |
-
The template argument list of a primary template is a template argument
|
| 127 |
-
list in which the nᵗʰ template argument has the value of the nᵗʰ
|
| 128 |
-
template parameter of the class template. If the nᵗʰ template parameter
|
| 129 |
-
is a template parameter pack [[temp.variadic]], the nᵗʰ template
|
| 130 |
-
argument is a pack expansion [[temp.variadic]] whose pattern is the name
|
| 131 |
-
of the template parameter pack.
|
| 132 |
|
| 133 |
A template argument that is equivalent to a template parameter can be
|
| 134 |
used in place of that template parameter in a reference to the current
|
| 135 |
instantiation. For a template *type-parameter*, a template argument is
|
| 136 |
equivalent to a template parameter if it denotes the same type. For a
|
|
@@ -212,32 +161,17 @@ template<class T> struct A<T>::B::C : A<T> {
|
|
| 212 |
|
| 213 |
— *end example*]
|
| 214 |
|
| 215 |
— *end note*]
|
| 216 |
|
| 217 |
-
A name is a *member of
|
|
|
|
| 218 |
|
| 219 |
-
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
template. — *end note*]
|
| 224 |
-
- A *qualified-id* in which the *nested-name-specifier* refers to the
|
| 225 |
-
current instantiation and that, when looked up, refers to at least one
|
| 226 |
-
member of a class that is the current instantiation or a non-dependent
|
| 227 |
-
base class thereof. \[*Note 4*: If no such member is found, and the
|
| 228 |
-
current instantiation has any dependent base classes, then the
|
| 229 |
-
*qualified-id* is a member of an unknown specialization; see
|
| 230 |
-
below. — *end note*]
|
| 231 |
-
- An *id-expression* denoting the member in a class member access
|
| 232 |
-
expression [[expr.ref]] for which the type of the object expression is
|
| 233 |
-
the current instantiation, and the *id-expression*, when looked up
|
| 234 |
-
[[basic.lookup.classref]], refers to at least one member of a class
|
| 235 |
-
that is the current instantiation or a non-dependent base class
|
| 236 |
-
thereof. \[*Note 5*: If no such member is found, and the current
|
| 237 |
-
instantiation has any dependent base classes, then the *id-expression*
|
| 238 |
-
is a member of an unknown specialization; see below. — *end note*]
|
| 239 |
|
| 240 |
[*Example 3*:
|
| 241 |
|
| 242 |
``` cpp
|
| 243 |
template <class T> class A {
|
|
@@ -253,66 +187,51 @@ template <class T> int A<T>::f() {
|
|
| 253 |
}
|
| 254 |
```
|
| 255 |
|
| 256 |
— *end example*]
|
| 257 |
|
| 258 |
-
A name
|
| 259 |
-
member of the current instantiation that, when
|
| 260 |
-
|
|
|
|
|
|
|
| 261 |
|
| 262 |
-
A name is
|
| 263 |
|
| 264 |
-
-
|
| 265 |
-
dependent
|
| 266 |
-
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
- the type of the object expression is the current instantiation, the
|
| 274 |
-
current instantiation has at least one dependent base class, and
|
| 275 |
-
name lookup of the *id-expression* does not find a member of a class
|
| 276 |
-
that is the current instantiation or a non-dependent base class
|
| 277 |
-
thereof; or
|
| 278 |
-
- the type of the object expression is not the current instantiation
|
| 279 |
-
and the object expression is type-dependent.
|
| 280 |
-
|
| 281 |
-
If a *qualified-id* in which the *nested-name-specifier* refers to the
|
| 282 |
-
current instantiation is not a member of the current instantiation or a
|
| 283 |
-
member of an unknown specialization, the program is ill-formed even if
|
| 284 |
-
the template containing the *qualified-id* is not instantiated; no
|
| 285 |
-
diagnostic required. Similarly, if the *id-expression* in a class member
|
| 286 |
-
access expression for which the type of the object expression is the
|
| 287 |
-
current instantiation does not refer to a member of the current
|
| 288 |
-
instantiation or a member of an unknown specialization, the program is
|
| 289 |
-
ill-formed even if the template containing the member access expression
|
| 290 |
-
is not instantiated; no diagnostic required.
|
| 291 |
|
| 292 |
[*Example 4*:
|
| 293 |
|
| 294 |
``` cpp
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
A<T>::type i; // OK: refers to a member of the current instantiation
|
| 299 |
-
typename A<T>::other j; // error: neither a member of the current instantiation nor
|
| 300 |
-
// a member of an unknown specialization
|
| 301 |
-
}
|
| 302 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
```
|
| 304 |
|
| 305 |
— *end example*]
|
| 306 |
|
| 307 |
If, for a given set of template arguments, a specialization of a
|
| 308 |
template is instantiated that refers to a member of the current
|
| 309 |
-
instantiation with a
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
lookup
|
| 313 |
-
context, name lookup is ambiguous.
|
| 314 |
|
| 315 |
[*Example 5*:
|
| 316 |
|
| 317 |
``` cpp
|
| 318 |
struct A {
|
|
@@ -328,84 +247,87 @@ struct C : A, T {
|
|
| 328 |
int f() { return this->m; } // finds A::m in the template definition context
|
| 329 |
int g() { return m; } // finds A::m in the template definition context
|
| 330 |
};
|
| 331 |
|
| 332 |
template int C<B>::f(); // error: finds both A::m and B::m
|
| 333 |
-
template int C<B>::g(); // OK
|
| 334 |
-
// does not occur in the template definition context; see~[class.mfct.non
|
| 335 |
```
|
| 336 |
|
| 337 |
— *end example*]
|
| 338 |
|
| 339 |
A type is dependent if it is
|
| 340 |
|
| 341 |
- a template parameter,
|
| 342 |
-
-
|
| 343 |
-
- a nested class or enumeration that is a
|
| 344 |
-
current instantiation,
|
| 345 |
- a cv-qualified type where the cv-unqualified type is dependent,
|
| 346 |
- a compound type constructed from any dependent type,
|
| 347 |
- an array type whose element type is dependent or whose bound (if any)
|
| 348 |
is value-dependent,
|
|
|
|
|
|
|
| 349 |
- a function type whose exception specification is value-dependent,
|
| 350 |
- denoted by a *simple-template-id* in which either the template name is
|
| 351 |
a template parameter or any of the template arguments is a dependent
|
| 352 |
type or an expression that is type-dependent or value-dependent or is
|
| 353 |
-
a pack expansion
|
| 354 |
-
[[class.pre]] of a class template used without a
|
| 355 |
-
*template-argument-list*. — *end note*] , or
|
| 356 |
- denoted by `decltype(`*expression*`)`, where *expression* is
|
| 357 |
type-dependent [[temp.dep.expr]].
|
| 358 |
|
| 359 |
-
[*Note
|
| 360 |
simply refer to other types, a name that refers to a typedef that is a
|
| 361 |
member of the current instantiation is dependent only if the type
|
| 362 |
referred to is dependent. — *end note*]
|
| 363 |
|
| 364 |
#### Type-dependent expressions <a id="temp.dep.expr">[[temp.dep.expr]]</a>
|
| 365 |
|
| 366 |
Except as described below, an expression is type-dependent if any
|
| 367 |
subexpression is type-dependent.
|
| 368 |
|
| 369 |
-
`this`
|
| 370 |
-
|
| 371 |
-
is type-dependent if the class type of the enclosing member function is
|
| 372 |
dependent [[temp.dep.type]].
|
| 373 |
|
| 374 |
-
An *id-expression* is type-dependent if it is
|
| 375 |
-
|
| 376 |
|
| 377 |
-
-
|
| 378 |
-
|
| 379 |
-
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
-
|
| 383 |
-
|
| 384 |
-
the initializer is type-dependent,
|
| 385 |
-
- an *identifier* associated by name lookup with one or more
|
| 386 |
-
declarations of member functions of the current instantiation declared
|
| 387 |
-
with a return type that contains a placeholder type,
|
| 388 |
-
- an *identifier* associated by name lookup with a structured binding
|
| 389 |
-
declaration [[dcl.struct.bind]] whose *brace-or-equal-initializer* is
|
| 390 |
type-dependent,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
- the *identifier* `__func__` [[dcl.fct.def.general]], where any
|
| 392 |
enclosing function is a template, a member of a class template, or a
|
| 393 |
generic lambda,
|
| 394 |
-
- a *template-id* that is dependent,
|
| 395 |
- a *conversion-function-id* that specifies a dependent type, or
|
| 396 |
-
-
|
| 397 |
-
an unknown specialization;
|
| 398 |
|
| 399 |
or if it names a dependent member of the current instantiation that is a
|
| 400 |
static data member of type “array of unknown bound of `T`” for some `T`
|
| 401 |
[[temp.static]]. Expressions of the following forms are type-dependent
|
| 402 |
-
only if the type specified by the *type-id*, *simple-type-specifier*
|
| 403 |
-
*new-type-id* is dependent, even if any
|
|
|
|
| 404 |
|
| 405 |
``` bnf
|
| 406 |
simple-type-specifier '(' expression-listₒₚₜ ')'
|
|
|
|
|
|
|
|
|
|
| 407 |
'::'ₒₚₜ new new-placementₒₚₜ new-type-id new-initializerₒₚₜ
|
| 408 |
'::'ₒₚₜ new new-placementₒₚₜ '(' type-id ')' new-initializerₒₚₜ
|
| 409 |
dynamic_cast '<' type-id '>' '(' expression ')'
|
| 410 |
static_cast '<' type-id '>' '(' expression ')'
|
| 411 |
const_cast '<' type-id '>' '(' expression ')'
|
|
@@ -432,21 +354,19 @@ noexcept '(' expression ')'
|
|
| 432 |
|
| 433 |
[*Note 1*: For the standard library macro `offsetof`, see
|
| 434 |
[[support.types]]. — *end note*]
|
| 435 |
|
| 436 |
A class member access expression [[expr.ref]] is type-dependent if the
|
|
|
|
| 437 |
expression refers to a member of the current instantiation and the type
|
| 438 |
-
of the referenced member is dependent
|
| 439 |
-
expression refers to a member of an unknown specialization.
|
| 440 |
|
| 441 |
[*Note 2*: In an expression of the form `x.y` or `xp->y` the type of
|
| 442 |
the expression is usually the type of the member `y` of the class of `x`
|
| 443 |
(or the class pointed to by `xp`). However, if `x` or `xp` refers to a
|
| 444 |
dependent type that is not the current instantiation, the type of `y` is
|
| 445 |
-
always dependent.
|
| 446 |
-
refers to the current instantiation, the type of `y` is the type of the
|
| 447 |
-
class member access expression. — *end note*]
|
| 448 |
|
| 449 |
A *braced-init-list* is type-dependent if any element is type-dependent
|
| 450 |
or is a pack expansion.
|
| 451 |
|
| 452 |
A *fold-expression* is type-dependent.
|
|
@@ -523,9 +443,8 @@ the constant expression it specifies is value-dependent.
|
|
| 523 |
Furthermore, a non-type *template-argument* is dependent if the
|
| 524 |
corresponding non-type *template-parameter* is of reference or pointer
|
| 525 |
type and the *template-argument* designates or points to a member of the
|
| 526 |
current instantiation or a member of a dependent type.
|
| 527 |
|
| 528 |
-
A template *template-
|
| 529 |
-
*template-parameter* or
|
| 530 |
-
an unknown specialization.
|
| 531 |
|
|
|
|
| 1 |
### Dependent names <a id="temp.dep">[[temp.dep]]</a>
|
| 2 |
|
| 3 |
+
#### General <a id="temp.dep.general">[[temp.dep.general]]</a>
|
| 4 |
+
|
| 5 |
Inside a template, some constructs have semantics which may differ from
|
| 6 |
one instantiation to another. Such a construct *depends* on the template
|
| 7 |
parameters. In particular, types and expressions may depend on the type
|
| 8 |
and/or value of template parameters (as determined by the template
|
| 9 |
arguments) and this determines the context for name lookup for certain
|
| 10 |
names. An expression may be *type-dependent* (that is, its type may
|
| 11 |
depend on a template parameter) or *value-dependent* (that is, its value
|
| 12 |
when evaluated as a constant expression [[expr.const]] may depend on a
|
| 13 |
+
template parameter) as described below.
|
| 14 |
|
| 15 |
+
A *dependent call* is an expression, possibly formed as a non-member
|
| 16 |
+
candidate for an operator [[over.match.oper]], of the form:
|
| 17 |
|
| 18 |
``` bnf
|
| 19 |
postfix-expression '(' expression-listₒₚₜ ')'
|
| 20 |
```
|
| 21 |
|
| 22 |
+
where the *postfix-expression* is an *unqualified-id* and
|
|
|
|
| 23 |
|
| 24 |
- any of the expressions in the *expression-list* is a pack expansion
|
| 25 |
+
[[temp.variadic]], or
|
| 26 |
- any of the expressions or *braced-init-list*s in the *expression-list*
|
| 27 |
is type-dependent [[temp.dep.expr]], or
|
| 28 |
- the *unqualified-id* is a *template-id* in which any of the template
|
| 29 |
arguments depends on a template parameter.
|
| 30 |
|
| 31 |
+
The component name of an *unqualified-id* [[expr.prim.id.unqual]] is
|
| 32 |
+
dependent if
|
| 33 |
|
| 34 |
+
- it is a *conversion-function-id* whose *conversion-type-id* is
|
| 35 |
+
dependent, or
|
| 36 |
+
- it is `operator=` and the current class is a templated entity, or
|
| 37 |
+
- the *unqualified-id* is the *postfix-expression* in a dependent call.
|
| 38 |
+
|
| 39 |
+
[*Note 1*: Such names are looked up only at the point of the template
|
| 40 |
+
instantiation [[temp.point]] in both the context of the template
|
| 41 |
+
definition and the context of the point of instantiation
|
| 42 |
[[temp.dep.candidate]]. — *end note*]
|
| 43 |
|
| 44 |
[*Example 1*:
|
| 45 |
|
| 46 |
``` cpp
|
|
|
|
| 56 |
The base class name `B<T>`, the type name `T::A`, the names `B<T>::i`
|
| 57 |
and `pb->j` explicitly depend on the *template-parameter*.
|
| 58 |
|
| 59 |
— *end example*]
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
#### Dependent types <a id="temp.dep.type">[[temp.dep.type]]</a>
|
| 62 |
|
| 63 |
+
A name or *template-id* refers to the *current instantiation* if it is
|
| 64 |
|
| 65 |
- in the definition of a class template, a nested class of a class
|
| 66 |
template, a member of a class template, or a member of a nested class
|
| 67 |
of a class template, the injected-class-name [[class.pre]] of the
|
| 68 |
class template or nested class,
|
| 69 |
- in the definition of a primary class template or a member of a primary
|
| 70 |
class template, the name of the class template followed by the
|
| 71 |
+
template argument list of its *template-head* [[temp.arg]] enclosed in
|
| 72 |
+
`<>` (or an equivalent template alias specialization),
|
| 73 |
- in the definition of a nested class of a class template, the name of
|
| 74 |
the nested class referenced as a member of the current instantiation,
|
| 75 |
or
|
| 76 |
+
- in the definition of a class template partial specialization or a
|
| 77 |
+
member of a class template partial specialization, the name of the
|
| 78 |
+
class template followed by a template argument list equivalent to that
|
| 79 |
+
of the partial specialization [[temp.spec.partial]] enclosed in `<>`
|
| 80 |
+
(or an equivalent template alias specialization).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
A template argument that is equivalent to a template parameter can be
|
| 83 |
used in place of that template parameter in a reference to the current
|
| 84 |
instantiation. For a template *type-parameter*, a template argument is
|
| 85 |
equivalent to a template parameter if it denotes the same type. For a
|
|
|
|
| 161 |
|
| 162 |
— *end example*]
|
| 163 |
|
| 164 |
— *end note*]
|
| 165 |
|
| 166 |
+
A qualified [[basic.lookup.qual]] or unqualified name is a *member of
|
| 167 |
+
the current instantiation* if
|
| 168 |
|
| 169 |
+
- its lookup context, if it is a qualified name, is the current
|
| 170 |
+
instantiation, and
|
| 171 |
+
- lookup for it finds any member of a class that is the current
|
| 172 |
+
instantiation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
[*Example 3*:
|
| 175 |
|
| 176 |
``` cpp
|
| 177 |
template <class T> class A {
|
|
|
|
| 187 |
}
|
| 188 |
```
|
| 189 |
|
| 190 |
— *end example*]
|
| 191 |
|
| 192 |
+
A qualified or unqualified name names a *dependent member of the current
|
| 193 |
+
instantiation* if it is a member of the current instantiation that, when
|
| 194 |
+
looked up, refers to at least one member declaration (including a
|
| 195 |
+
*using-declarator* whose terminal name is dependent) of a class that is
|
| 196 |
+
the current instantiation.
|
| 197 |
|
| 198 |
+
A qualified name [[basic.lookup.qual]] is dependent if
|
| 199 |
|
| 200 |
+
- it is a *conversion-function-id* whose *conversion-type-id* is
|
| 201 |
+
dependent, or
|
| 202 |
+
- its lookup context is dependent and is not the current instantiation,
|
| 203 |
+
or
|
| 204 |
+
- its lookup context is the current instantiation and it is
|
| 205 |
+
`operator=`,[^11] or
|
| 206 |
+
- its lookup context is the current instantiation and has at least one
|
| 207 |
+
dependent base class, and qualified name lookup for the name finds
|
| 208 |
+
nothing [[basic.lookup.qual]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
[*Example 4*:
|
| 211 |
|
| 212 |
``` cpp
|
| 213 |
+
struct A {
|
| 214 |
+
using B = int;
|
| 215 |
+
A f();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
};
|
| 217 |
+
struct C : A {};
|
| 218 |
+
template<class T>
|
| 219 |
+
void g(T t) {
|
| 220 |
+
decltype(t.A::f())::B i; // error: typename needed to interpret B as a type
|
| 221 |
+
}
|
| 222 |
+
template void g(C); // … even though A is ::A here
|
| 223 |
```
|
| 224 |
|
| 225 |
— *end example*]
|
| 226 |
|
| 227 |
If, for a given set of template arguments, a specialization of a
|
| 228 |
template is instantiated that refers to a member of the current
|
| 229 |
+
instantiation with a qualified name, the name is looked up in the
|
| 230 |
+
template instantiation context. If the result of this lookup differs
|
| 231 |
+
from the result of name lookup in the template definition context, name
|
| 232 |
+
lookup is ambiguous.
|
|
|
|
| 233 |
|
| 234 |
[*Example 5*:
|
| 235 |
|
| 236 |
``` cpp
|
| 237 |
struct A {
|
|
|
|
| 247 |
int f() { return this->m; } // finds A::m in the template definition context
|
| 248 |
int g() { return m; } // finds A::m in the template definition context
|
| 249 |
};
|
| 250 |
|
| 251 |
template int C<B>::f(); // error: finds both A::m and B::m
|
| 252 |
+
template int C<B>::g(); // OK, transformation to class member access syntax
|
| 253 |
+
// does not occur in the template definition context; see~[class.mfct.non.static]
|
| 254 |
```
|
| 255 |
|
| 256 |
— *end example*]
|
| 257 |
|
| 258 |
A type is dependent if it is
|
| 259 |
|
| 260 |
- a template parameter,
|
| 261 |
+
- denoted by a dependent (qualified) name,
|
| 262 |
+
- a nested class or enumeration that is a direct member of a class that
|
| 263 |
+
is the current instantiation,
|
| 264 |
- a cv-qualified type where the cv-unqualified type is dependent,
|
| 265 |
- a compound type constructed from any dependent type,
|
| 266 |
- an array type whose element type is dependent or whose bound (if any)
|
| 267 |
is value-dependent,
|
| 268 |
+
- a function type whose parameters include one or more function
|
| 269 |
+
parameter packs,
|
| 270 |
- a function type whose exception specification is value-dependent,
|
| 271 |
- denoted by a *simple-template-id* in which either the template name is
|
| 272 |
a template parameter or any of the template arguments is a dependent
|
| 273 |
type or an expression that is type-dependent or value-dependent or is
|
| 274 |
+
a pack expansion,[^12] or
|
|
|
|
|
|
|
| 275 |
- denoted by `decltype(`*expression*`)`, where *expression* is
|
| 276 |
type-dependent [[temp.dep.expr]].
|
| 277 |
|
| 278 |
+
[*Note 3*: Because typedefs do not introduce new types, but instead
|
| 279 |
simply refer to other types, a name that refers to a typedef that is a
|
| 280 |
member of the current instantiation is dependent only if the type
|
| 281 |
referred to is dependent. — *end note*]
|
| 282 |
|
| 283 |
#### Type-dependent expressions <a id="temp.dep.expr">[[temp.dep.expr]]</a>
|
| 284 |
|
| 285 |
Except as described below, an expression is type-dependent if any
|
| 286 |
subexpression is type-dependent.
|
| 287 |
|
| 288 |
+
`this` is type-dependent if the current class [[expr.prim.this]] is
|
|
|
|
|
|
|
| 289 |
dependent [[temp.dep.type]].
|
| 290 |
|
| 291 |
+
An *id-expression* is type-dependent if it is a *template-id* that is
|
| 292 |
+
not a concept-id and is dependent; or if its terminal name is
|
| 293 |
|
| 294 |
+
- associated by name lookup with one or more declarations declared with
|
| 295 |
+
a dependent type,
|
| 296 |
+
- associated by name lookup with a non-type *template-parameter*
|
| 297 |
+
declared with a type that contains a placeholder type
|
| 298 |
+
[[dcl.spec.auto]],
|
| 299 |
+
- associated by name lookup with a variable declared with a type that
|
| 300 |
+
contains a placeholder type [[dcl.spec.auto]] where the initializer is
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
type-dependent,
|
| 302 |
+
- associated by name lookup with one or more declarations of member
|
| 303 |
+
functions of a class that is the current instantiation declared with a
|
| 304 |
+
return type that contains a placeholder type,
|
| 305 |
+
- associated by name lookup with a structured binding declaration
|
| 306 |
+
[[dcl.struct.bind]] whose *brace-or-equal-initializer* is
|
| 307 |
+
type-dependent,
|
| 308 |
+
- associated by name lookup with an entity captured by copy
|
| 309 |
+
[[expr.prim.lambda.capture]] in a *lambda-expression* that has an
|
| 310 |
+
explicit object parameter whose type is dependent [[dcl.fct]],
|
| 311 |
- the *identifier* `__func__` [[dcl.fct.def.general]], where any
|
| 312 |
enclosing function is a template, a member of a class template, or a
|
| 313 |
generic lambda,
|
|
|
|
| 314 |
- a *conversion-function-id* that specifies a dependent type, or
|
| 315 |
+
- dependent
|
|
|
|
| 316 |
|
| 317 |
or if it names a dependent member of the current instantiation that is a
|
| 318 |
static data member of type “array of unknown bound of `T`” for some `T`
|
| 319 |
[[temp.static]]. Expressions of the following forms are type-dependent
|
| 320 |
+
only if the type specified by the *type-id*, *simple-type-specifier*,
|
| 321 |
+
*typename-specifier*, or *new-type-id* is dependent, even if any
|
| 322 |
+
subexpression is type-dependent:
|
| 323 |
|
| 324 |
``` bnf
|
| 325 |
simple-type-specifier '(' expression-listₒₚₜ ')'
|
| 326 |
+
simple-type-specifier braced-init-list
|
| 327 |
+
typename-specifier '(' expression-listₒₚₜ ')'
|
| 328 |
+
typename-specifier braced-init-list
|
| 329 |
'::'ₒₚₜ new new-placementₒₚₜ new-type-id new-initializerₒₚₜ
|
| 330 |
'::'ₒₚₜ new new-placementₒₚₜ '(' type-id ')' new-initializerₒₚₜ
|
| 331 |
dynamic_cast '<' type-id '>' '(' expression ')'
|
| 332 |
static_cast '<' type-id '>' '(' expression ')'
|
| 333 |
const_cast '<' type-id '>' '(' expression ')'
|
|
|
|
| 354 |
|
| 355 |
[*Note 1*: For the standard library macro `offsetof`, see
|
| 356 |
[[support.types]]. — *end note*]
|
| 357 |
|
| 358 |
A class member access expression [[expr.ref]] is type-dependent if the
|
| 359 |
+
terminal name of its *id-expression*, if any, is dependent or the
|
| 360 |
expression refers to a member of the current instantiation and the type
|
| 361 |
+
of the referenced member is dependent.
|
|
|
|
| 362 |
|
| 363 |
[*Note 2*: In an expression of the form `x.y` or `xp->y` the type of
|
| 364 |
the expression is usually the type of the member `y` of the class of `x`
|
| 365 |
(or the class pointed to by `xp`). However, if `x` or `xp` refers to a
|
| 366 |
dependent type that is not the current instantiation, the type of `y` is
|
| 367 |
+
always dependent. — *end note*]
|
|
|
|
|
|
|
| 368 |
|
| 369 |
A *braced-init-list* is type-dependent if any element is type-dependent
|
| 370 |
or is a pack expansion.
|
| 371 |
|
| 372 |
A *fold-expression* is type-dependent.
|
|
|
|
| 443 |
Furthermore, a non-type *template-argument* is dependent if the
|
| 444 |
corresponding non-type *template-parameter* is of reference or pointer
|
| 445 |
type and the *template-argument* designates or points to a member of the
|
| 446 |
current instantiation or a member of a dependent type.
|
| 447 |
|
| 448 |
+
A template *template-parameter* is dependent if it names a
|
| 449 |
+
*template-parameter* or its terminal name is dependent.
|
|
|
|
| 450 |
|