tmp/tmp7use179_/{from.md → to.md}
RENAMED
|
@@ -34,21 +34,22 @@ can be used in place of that template parameter in a reference to the
|
|
| 34 |
current instantiation. In the case of a non-type template argument, the
|
| 35 |
argument must have been given the value of the template parameter and
|
| 36 |
not an expression in which the template parameter appears as a
|
| 37 |
subexpression.
|
| 38 |
|
|
|
|
|
|
|
| 39 |
``` cpp
|
| 40 |
template <class T> class A {
|
| 41 |
A* p1; // A is the current instantiation
|
| 42 |
A<T>* p2; // A<T> is the current instantiation
|
| 43 |
A<T*> p3; // A<T*> is not the current instantiation
|
| 44 |
::A<T>* p4; // ::A<T> is the current instantiation
|
| 45 |
class B {
|
| 46 |
B* p1; // B is the current instantiation
|
| 47 |
A<T>::B* p2; // A<T>::B is the current instantiation
|
| 48 |
-
typename A<T*>::B* p3; // A<T*>::B is not the
|
| 49 |
-
// current instantiation
|
| 50 |
};
|
| 51 |
};
|
| 52 |
|
| 53 |
template <class T> class A<T*> {
|
| 54 |
A<T*>* p1; // A<T*> is the current instantiation
|
|
@@ -66,30 +67,64 @@ template <class T1, class T2, int I> struct B {
|
|
| 66 |
B<my_T1, T2, my_I2>* b4; // not the current instantiation
|
| 67 |
B<my_T1, T2, my_I3>* b5; // refers to the current instantiation
|
| 68 |
};
|
| 69 |
```
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
A name is a *member of the current instantiation* if it is
|
| 72 |
|
| 73 |
- An unqualified name that, when looked up, refers to at least one
|
| 74 |
member of a class that is the current instantiation or a non-dependent
|
| 75 |
-
base class thereof. This can only occur when looking up a
|
| 76 |
-
scope enclosed by the definition of a class
|
|
|
|
| 77 |
- A *qualified-id* in which the *nested-name-specifier* refers to the
|
| 78 |
current instantiation and that, when looked up, refers to at least one
|
| 79 |
member of a class that is the current instantiation or a non-dependent
|
| 80 |
-
base class thereof.
|
| 81 |
-
instantiation has any dependent base classes, then the
|
| 82 |
-
is a member of an unknown specialization; see
|
|
|
|
| 83 |
- An *id-expression* denoting the member in a class member access
|
| 84 |
expression ([[expr.ref]]) for which the type of the object expression
|
| 85 |
is the current instantiation, and the *id-expression*, when looked
|
| 86 |
up ([[basic.lookup.classref]]), refers to at least one member of a
|
| 87 |
class that is the current instantiation or a non-dependent base class
|
| 88 |
-
thereof.
|
| 89 |
-
any dependent base classes, then the *id-expression*
|
| 90 |
-
unknown specialization; see below.
|
|
|
|
|
|
|
| 91 |
|
| 92 |
``` cpp
|
| 93 |
template <class T> class A {
|
| 94 |
static const int i = 5;
|
| 95 |
int n1[i]; // i refers to a member of the current instantiation
|
|
@@ -101,10 +136,12 @@ template <class T> class A {
|
|
| 101 |
template <class T> int A<T>::f() {
|
| 102 |
return i; // i refers to a member of the current instantiation
|
| 103 |
}
|
| 104 |
```
|
| 105 |
|
|
|
|
|
|
|
| 106 |
A name is a *dependent member of the current instantiation* if it is a
|
| 107 |
member of the current instantiation that, when looked up, refers to at
|
| 108 |
least one member of a class that is the current instantiation.
|
| 109 |
|
| 110 |
A name is a *member of an unknown specialization* if it is
|
|
@@ -135,10 +172,12 @@ access expression for which the type of the object expression is the
|
|
| 135 |
current instantiation does not refer to a member of the current
|
| 136 |
instantiation or a member of an unknown specialization, the program is
|
| 137 |
ill-formed even if the template containing the member access expression
|
| 138 |
is not instantiated; no diagnostic required.
|
| 139 |
|
|
|
|
|
|
|
| 140 |
``` cpp
|
| 141 |
template<class T> class A {
|
| 142 |
typedef int type;
|
| 143 |
void f() {
|
| 144 |
A<T>::type i; // OK: refers to a member of the current instantiation
|
|
@@ -146,38 +185,64 @@ template<class T> class A {
|
|
| 146 |
// a member of an unknown specialization
|
| 147 |
}
|
| 148 |
};
|
| 149 |
```
|
| 150 |
|
|
|
|
|
|
|
| 151 |
If, for a given set of template arguments, a specialization of a
|
| 152 |
template is instantiated that refers to a member of the current
|
| 153 |
instantiation with a *qualified-id* or class member access expression,
|
| 154 |
the name in the *qualified-id* or class member access expression is
|
| 155 |
looked up in the template instantiation context. If the result of this
|
| 156 |
lookup differs from the result of name lookup in the template definition
|
| 157 |
-
context, name lookup is ambiguous.
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
A type is dependent if it is
|
| 164 |
|
| 165 |
- a template parameter,
|
| 166 |
- a member of an unknown specialization,
|
| 167 |
- a nested class or enumeration that is a dependent member of the
|
| 168 |
current instantiation,
|
| 169 |
- a cv-qualified type where the cv-unqualified type is dependent,
|
| 170 |
- a compound type constructed from any dependent type,
|
| 171 |
-
- an array type
|
| 172 |
-
|
|
|
|
| 173 |
- a *simple-template-id* in which either the template name is a template
|
| 174 |
parameter or any of the template arguments is a dependent type or an
|
| 175 |
-
expression that is type-dependent or value-dependent
|
|
|
|
|
|
|
|
|
|
| 176 |
- denoted by `decltype(`*expression*`)`, where *expression* is
|
| 177 |
type-dependent ([[temp.dep.expr]]).
|
| 178 |
|
| 179 |
-
Because typedefs do not introduce new types, but instead
|
| 180 |
-
other types, a name that refers to a typedef that is a
|
| 181 |
-
current instantiation is dependent only if the type
|
| 182 |
-
dependent.
|
| 183 |
|
|
|
|
| 34 |
current instantiation. In the case of a non-type template argument, the
|
| 35 |
argument must have been given the value of the template parameter and
|
| 36 |
not an expression in which the template parameter appears as a
|
| 37 |
subexpression.
|
| 38 |
|
| 39 |
+
[*Example 1*:
|
| 40 |
+
|
| 41 |
``` cpp
|
| 42 |
template <class T> class A {
|
| 43 |
A* p1; // A is the current instantiation
|
| 44 |
A<T>* p2; // A<T> is the current instantiation
|
| 45 |
A<T*> p3; // A<T*> is not the current instantiation
|
| 46 |
::A<T>* p4; // ::A<T> is the current instantiation
|
| 47 |
class B {
|
| 48 |
B* p1; // B is the current instantiation
|
| 49 |
A<T>::B* p2; // A<T>::B is the current instantiation
|
| 50 |
+
typename A<T*>::B* p3; // A<T*>::B is not the current instantiation
|
|
|
|
| 51 |
};
|
| 52 |
};
|
| 53 |
|
| 54 |
template <class T> class A<T*> {
|
| 55 |
A<T*>* p1; // A<T*> is the current instantiation
|
|
|
|
| 67 |
B<my_T1, T2, my_I2>* b4; // not the current instantiation
|
| 68 |
B<my_T1, T2, my_I3>* b5; // refers to the current instantiation
|
| 69 |
};
|
| 70 |
```
|
| 71 |
|
| 72 |
+
— *end example*]
|
| 73 |
+
|
| 74 |
+
A *dependent base class* is a base class that is a dependent type and is
|
| 75 |
+
not the current instantiation.
|
| 76 |
+
|
| 77 |
+
[*Note 1*:
|
| 78 |
+
|
| 79 |
+
A base class can be the current instantiation in the case of a nested
|
| 80 |
+
class naming an enclosing class as a base.
|
| 81 |
+
|
| 82 |
+
[*Example 2*:
|
| 83 |
+
|
| 84 |
+
``` cpp
|
| 85 |
+
template<class T> struct A {
|
| 86 |
+
typedef int M;
|
| 87 |
+
struct B {
|
| 88 |
+
typedef void M;
|
| 89 |
+
struct C;
|
| 90 |
+
};
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
template<class T> struct A<T>::B::C : A<T> {
|
| 94 |
+
M m; // OK, A<T>::M
|
| 95 |
+
};
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
— *end example*]
|
| 99 |
+
|
| 100 |
+
— *end note*]
|
| 101 |
+
|
| 102 |
A name is a *member of the current instantiation* if it is
|
| 103 |
|
| 104 |
- An unqualified name that, when looked up, refers to at least one
|
| 105 |
member of a class that is the current instantiation or a non-dependent
|
| 106 |
+
base class thereof. \[*Note 2*: This can only occur when looking up a
|
| 107 |
+
name in a scope enclosed by the definition of a class
|
| 108 |
+
template. — *end note*]
|
| 109 |
- A *qualified-id* in which the *nested-name-specifier* refers to the
|
| 110 |
current instantiation and that, when looked up, refers to at least one
|
| 111 |
member of a class that is the current instantiation or a non-dependent
|
| 112 |
+
base class thereof. \[*Note 3*: If no such member is found, and the
|
| 113 |
+
current instantiation has any dependent base classes, then the
|
| 114 |
+
*qualified-id* is a member of an unknown specialization; see
|
| 115 |
+
below. — *end note*]
|
| 116 |
- An *id-expression* denoting the member in a class member access
|
| 117 |
expression ([[expr.ref]]) for which the type of the object expression
|
| 118 |
is the current instantiation, and the *id-expression*, when looked
|
| 119 |
up ([[basic.lookup.classref]]), refers to at least one member of a
|
| 120 |
class that is the current instantiation or a non-dependent base class
|
| 121 |
+
thereof. \[*Note 4*: If no such member is found, and the current
|
| 122 |
+
instantiation has any dependent base classes, then the *id-expression*
|
| 123 |
+
is a member of an unknown specialization; see below. — *end note*]
|
| 124 |
+
|
| 125 |
+
[*Example 3*:
|
| 126 |
|
| 127 |
``` cpp
|
| 128 |
template <class T> class A {
|
| 129 |
static const int i = 5;
|
| 130 |
int n1[i]; // i refers to a member of the current instantiation
|
|
|
|
| 136 |
template <class T> int A<T>::f() {
|
| 137 |
return i; // i refers to a member of the current instantiation
|
| 138 |
}
|
| 139 |
```
|
| 140 |
|
| 141 |
+
— *end example*]
|
| 142 |
+
|
| 143 |
A name is a *dependent member of the current instantiation* if it is a
|
| 144 |
member of the current instantiation that, when looked up, refers to at
|
| 145 |
least one member of a class that is the current instantiation.
|
| 146 |
|
| 147 |
A name is a *member of an unknown specialization* if it is
|
|
|
|
| 172 |
current instantiation does not refer to a member of the current
|
| 173 |
instantiation or a member of an unknown specialization, the program is
|
| 174 |
ill-formed even if the template containing the member access expression
|
| 175 |
is not instantiated; no diagnostic required.
|
| 176 |
|
| 177 |
+
[*Example 4*:
|
| 178 |
+
|
| 179 |
``` cpp
|
| 180 |
template<class T> class A {
|
| 181 |
typedef int type;
|
| 182 |
void f() {
|
| 183 |
A<T>::type i; // OK: refers to a member of the current instantiation
|
|
|
|
| 185 |
// a member of an unknown specialization
|
| 186 |
}
|
| 187 |
};
|
| 188 |
```
|
| 189 |
|
| 190 |
+
— *end example*]
|
| 191 |
+
|
| 192 |
If, for a given set of template arguments, a specialization of a
|
| 193 |
template is instantiated that refers to a member of the current
|
| 194 |
instantiation with a *qualified-id* or class member access expression,
|
| 195 |
the name in the *qualified-id* or class member access expression is
|
| 196 |
looked up in the template instantiation context. If the result of this
|
| 197 |
lookup differs from the result of name lookup in the template definition
|
| 198 |
+
context, name lookup is ambiguous.
|
| 199 |
+
|
| 200 |
+
[*Example 5*:
|
| 201 |
+
|
| 202 |
+
``` cpp
|
| 203 |
+
struct A {
|
| 204 |
+
int m;
|
| 205 |
+
};
|
| 206 |
+
|
| 207 |
+
struct B {
|
| 208 |
+
int m;
|
| 209 |
+
};
|
| 210 |
+
|
| 211 |
+
template<typename T>
|
| 212 |
+
struct C : A, T {
|
| 213 |
+
int f() { return this->m; } // finds A::m in the template definition context
|
| 214 |
+
int g() { return m; } // finds A::m in the template definition context
|
| 215 |
+
};
|
| 216 |
+
|
| 217 |
+
template int C<B>::f(); // error: finds both A::m and B::m
|
| 218 |
+
template int C<B>::g(); // OK: transformation to class member access syntax
|
| 219 |
+
// does not occur in the template definition context; see~[class.mfct.non-static]
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
— *end example*]
|
| 223 |
|
| 224 |
A type is dependent if it is
|
| 225 |
|
| 226 |
- a template parameter,
|
| 227 |
- a member of an unknown specialization,
|
| 228 |
- a nested class or enumeration that is a dependent member of the
|
| 229 |
current instantiation,
|
| 230 |
- a cv-qualified type where the cv-unqualified type is dependent,
|
| 231 |
- a compound type constructed from any dependent type,
|
| 232 |
+
- an array type whose element type is dependent or whose bound (if any)
|
| 233 |
+
is value-dependent,
|
| 234 |
+
- a function type whose exception specification is value-dependent,
|
| 235 |
- a *simple-template-id* in which either the template name is a template
|
| 236 |
parameter or any of the template arguments is a dependent type or an
|
| 237 |
+
expression that is type-dependent or value-dependent or is a pack
|
| 238 |
+
expansion \[*Note 5*: This includes an injected-class-name (Clause
|
| 239 |
+
[[class]]) of a class template used without a
|
| 240 |
+
*template-argument-list*. — *end note*] , or
|
| 241 |
- denoted by `decltype(`*expression*`)`, where *expression* is
|
| 242 |
type-dependent ([[temp.dep.expr]]).
|
| 243 |
|
| 244 |
+
[*Note 6*: Because typedefs do not introduce new types, but instead
|
| 245 |
+
simply refer to other types, a name that refers to a typedef that is a
|
| 246 |
+
member of the current instantiation is dependent only if the type
|
| 247 |
+
referred to is dependent. — *end note*]
|
| 248 |
|