- tmp/tmpta2g_lti/{from.md → to.md} +687 -728
tmp/tmpta2g_lti/{from.md → to.md}
RENAMED
|
@@ -1,50 +1,462 @@
|
|
| 1 |
## Name lookup <a id="basic.lookup">[[basic.lookup]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
The name lookup rules apply uniformly to all names (including
|
| 4 |
*typedef-name*s [[dcl.typedef]], *namespace-name*s [[basic.namespace]],
|
| 5 |
and *class-name*s [[class.name]]) wherever the grammar allows such names
|
| 6 |
in the context discussed by a particular rule. Name lookup associates
|
| 7 |
the use of a name with a set of declarations [[basic.def]] of that name.
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
have succeeded
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
### Unqualified name lookup <a id="basic.lookup.unqual">[[basic.lookup.unqual]]</a>
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
namespace nominated by
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
[*Note 1*:
|
| 48 |
|
| 49 |
For purposes of determining (during parsing) whether an expression is a
|
| 50 |
*postfix-expression* for a function call, the usual name lookup rules
|
|
@@ -60,17 +472,17 @@ namespace N {
|
|
| 60 |
template <class T> int f(T);
|
| 61 |
template <class T> int g(T);
|
| 62 |
template <class T> int h(T);
|
| 63 |
}
|
| 64 |
|
| 65 |
-
int x = f<N::A>(N::A()); // OK
|
| 66 |
-
int y = g<N::A>(N::A()); // OK
|
| 67 |
int z = h<N::A>(N::A()); // error: h< does not begin a template-id
|
| 68 |
```
|
| 69 |
|
| 70 |
-
The rules
|
| 71 |
-
|
| 72 |
|
| 73 |
``` cpp
|
| 74 |
typedef int f;
|
| 75 |
namespace N {
|
| 76 |
struct A {
|
|
@@ -81,398 +493,79 @@ namespace N {
|
|
| 81 |
}
|
| 82 |
};
|
| 83 |
}
|
| 84 |
```
|
| 85 |
|
| 86 |
-
Because the expression is not a function call,
|
| 87 |
-
|
| 88 |
-
function `f` is not found.
|
| 89 |
|
| 90 |
— *end note*]
|
| 91 |
|
| 92 |
-
A name used in global scope, outside of any function, class or
|
| 93 |
-
user-declared namespace, shall be declared before its use in global
|
| 94 |
-
scope.
|
| 95 |
-
|
| 96 |
-
A name used in a user-declared namespace outside of the definition of
|
| 97 |
-
any function or class shall be declared before its use in that namespace
|
| 98 |
-
or before its use in a namespace enclosing its namespace.
|
| 99 |
-
|
| 100 |
-
In the definition of a function that is a member of namespace `N`, a
|
| 101 |
-
name used after the function’s *declarator-id*[^3] shall be declared
|
| 102 |
-
before its use in the block in which it is used or in one of its
|
| 103 |
-
enclosing blocks [[stmt.block]] or shall be declared before its use in
|
| 104 |
-
namespace `N` or, if `N` is a nested namespace, shall be declared before
|
| 105 |
-
its use in one of `N`’s enclosing namespaces.
|
| 106 |
-
|
| 107 |
-
[*Example 1*:
|
| 108 |
-
|
| 109 |
-
``` cpp
|
| 110 |
-
namespace A {
|
| 111 |
-
namespace N {
|
| 112 |
-
void f();
|
| 113 |
-
}
|
| 114 |
-
}
|
| 115 |
-
void A::N::f() {
|
| 116 |
-
i = 5;
|
| 117 |
-
// The following scopes are searched for a declaration of i:
|
| 118 |
-
// 1) outermost block scope of A::N::f, before the use of i
|
| 119 |
-
// 2) scope of namespace N
|
| 120 |
-
// 3) scope of namespace A
|
| 121 |
-
// 4) global scope, before the definition of A::N::f
|
| 122 |
-
}
|
| 123 |
-
```
|
| 124 |
-
|
| 125 |
-
— *end example*]
|
| 126 |
-
|
| 127 |
-
A name used in the definition of a class `X` [^4] outside of a
|
| 128 |
-
complete-class context [[class.mem]] of `X` shall be declared in one of
|
| 129 |
-
the following ways:
|
| 130 |
-
|
| 131 |
-
- before its use in class `X` or be a member of a base class of `X`
|
| 132 |
-
[[class.member.lookup]], or
|
| 133 |
-
- if `X` is a nested class of class `Y` [[class.nest]], before the
|
| 134 |
-
definition of `X` in `Y`, or shall be a member of a base class of `Y`
|
| 135 |
-
(this lookup applies in turn to `Y`’s enclosing classes, starting with
|
| 136 |
-
the innermost enclosing class),[^5] or
|
| 137 |
-
- if `X` is a local class [[class.local]] or is a nested class of a
|
| 138 |
-
local class, before the definition of class `X` in a block enclosing
|
| 139 |
-
the definition of class `X`, or
|
| 140 |
-
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 141 |
-
that is a member of `N`, or is a local class or a nested class within
|
| 142 |
-
a local class of a function that is a member of `N`, before the
|
| 143 |
-
definition of class `X` in namespace `N` or in one of `N`’s enclosing
|
| 144 |
-
namespaces.
|
| 145 |
-
|
| 146 |
-
[*Example 2*:
|
| 147 |
-
|
| 148 |
-
``` cpp
|
| 149 |
-
namespace M {
|
| 150 |
-
class B { };
|
| 151 |
-
}
|
| 152 |
-
```
|
| 153 |
-
|
| 154 |
-
``` cpp
|
| 155 |
-
namespace N {
|
| 156 |
-
class Y : public M::B {
|
| 157 |
-
class X {
|
| 158 |
-
int a[i];
|
| 159 |
-
};
|
| 160 |
-
};
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
// The following scopes are searched for a declaration of i:
|
| 164 |
-
// 1) scope of class N::Y::X, before the use of i
|
| 165 |
-
// 2) scope of class N::Y, before the definition of N::Y::X
|
| 166 |
-
// 3) scope of N::Y's base class M::B
|
| 167 |
-
// 4) scope of namespace N, before the definition of N::Y
|
| 168 |
-
// 5) global scope, before the definition of N
|
| 169 |
-
```
|
| 170 |
-
|
| 171 |
-
— *end example*]
|
| 172 |
-
|
| 173 |
-
[*Note 2*: When looking for a prior declaration of a class or function
|
| 174 |
-
introduced by a friend declaration, scopes outside of the innermost
|
| 175 |
-
enclosing namespace scope are not considered; see
|
| 176 |
-
[[namespace.memdef]]. — *end note*]
|
| 177 |
-
|
| 178 |
-
[*Note 3*: [[basic.scope.class]] further describes the restrictions on
|
| 179 |
-
the use of names in a class definition. [[class.nest]] further describes
|
| 180 |
-
the restrictions on the use of names in nested class definitions.
|
| 181 |
-
[[class.local]] further describes the restrictions on the use of names
|
| 182 |
-
in local class definitions. — *end note*]
|
| 183 |
-
|
| 184 |
-
For the members of a class `X`, a name used in a complete-class context
|
| 185 |
-
[[class.mem]] of `X` or in the definition of a class member outside of
|
| 186 |
-
the definition of `X`, following the member’s *declarator-id*[^6], shall
|
| 187 |
-
be declared in one of the following ways:
|
| 188 |
-
|
| 189 |
-
- before its use in the block in which it is used or in an enclosing
|
| 190 |
-
block [[stmt.block]], or
|
| 191 |
-
- shall be a member of class `X` or be a member of a base class of `X`
|
| 192 |
-
[[class.member.lookup]], or
|
| 193 |
-
- if `X` is a nested class of class `Y` [[class.nest]], shall be a
|
| 194 |
-
member of `Y`, or shall be a member of a base class of `Y` (this
|
| 195 |
-
lookup applies in turn to `Y`’s enclosing classes, starting with the
|
| 196 |
-
innermost enclosing class),[^7] or
|
| 197 |
-
- if `X` is a local class [[class.local]] or is a nested class of a
|
| 198 |
-
local class, before the definition of class `X` in a block enclosing
|
| 199 |
-
the definition of class `X`, or
|
| 200 |
-
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 201 |
-
that is a member of `N`, or is a local class or a nested class within
|
| 202 |
-
a local class of a function that is a member of `N`, before the use of
|
| 203 |
-
the name, in namespace `N` or in one of `N`’s enclosing namespaces.
|
| 204 |
-
|
| 205 |
-
[*Example 3*:
|
| 206 |
-
|
| 207 |
-
``` cpp
|
| 208 |
-
class B { };
|
| 209 |
-
namespace M {
|
| 210 |
-
namespace N {
|
| 211 |
-
class X : public B {
|
| 212 |
-
void f();
|
| 213 |
-
};
|
| 214 |
-
}
|
| 215 |
-
}
|
| 216 |
-
void M::N::X::f() {
|
| 217 |
-
i = 16;
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
// The following scopes are searched for a declaration of i:
|
| 221 |
-
// 1) outermost block scope of M::N::X::f, before the use of i
|
| 222 |
-
// 2) scope of class M::N::X
|
| 223 |
-
// 3) scope of M::N::X's base class B
|
| 224 |
-
// 4) scope of namespace M::N
|
| 225 |
-
// 5) scope of namespace M
|
| 226 |
-
// 6) global scope, before the definition of M::N::X::f
|
| 227 |
-
```
|
| 228 |
-
|
| 229 |
-
— *end example*]
|
| 230 |
-
|
| 231 |
-
[*Note 4*: [[class.mfct]] and [[class.static]] further describe the
|
| 232 |
-
restrictions on the use of names in member function definitions.
|
| 233 |
-
[[class.nest]] further describes the restrictions on the use of names in
|
| 234 |
-
the scope of nested classes. [[class.local]] further describes the
|
| 235 |
-
restrictions on the use of names in local class
|
| 236 |
-
definitions. — *end note*]
|
| 237 |
-
|
| 238 |
-
Name lookup for a name used in the definition of a friend function
|
| 239 |
-
[[class.friend]] defined inline in the class granting friendship shall
|
| 240 |
-
proceed as described for lookup in member function definitions. If the
|
| 241 |
-
friend function is not defined in the class granting friendship, name
|
| 242 |
-
lookup in the friend function definition shall proceed as described for
|
| 243 |
-
lookup in namespace member function definitions.
|
| 244 |
-
|
| 245 |
-
In a friend declaration naming a member function, a name used in the
|
| 246 |
-
function declarator and not part of a *template-argument* in the
|
| 247 |
-
*declarator-id* is first looked up in the scope of the member function’s
|
| 248 |
-
class [[class.member.lookup]]. If it is not found, or if the name is
|
| 249 |
-
part of a *template-argument* in the *declarator-id*, the look up is as
|
| 250 |
-
described for unqualified names in the definition of the class granting
|
| 251 |
-
friendship.
|
| 252 |
-
|
| 253 |
-
[*Example 4*:
|
| 254 |
-
|
| 255 |
-
``` cpp
|
| 256 |
-
struct A {
|
| 257 |
-
typedef int AT;
|
| 258 |
-
void f1(AT);
|
| 259 |
-
void f2(float);
|
| 260 |
-
template <class T> void f3();
|
| 261 |
-
};
|
| 262 |
-
struct B {
|
| 263 |
-
typedef char AT;
|
| 264 |
-
typedef float BT;
|
| 265 |
-
friend void A::f1(AT); // parameter type is A::AT
|
| 266 |
-
friend void A::f2(BT); // parameter type is B::BT
|
| 267 |
-
friend void A::f3<AT>(); // template argument is B::AT
|
| 268 |
-
};
|
| 269 |
-
```
|
| 270 |
-
|
| 271 |
-
— *end example*]
|
| 272 |
-
|
| 273 |
-
During the lookup for a name used as a default argument
|
| 274 |
-
[[dcl.fct.default]] in a function *parameter-declaration-clause* or used
|
| 275 |
-
in the *expression* of a *mem-initializer* for a constructor
|
| 276 |
-
[[class.base.init]], the function parameter names are visible and hide
|
| 277 |
-
the names of entities declared in the block, class or namespace scopes
|
| 278 |
-
containing the function declaration.
|
| 279 |
-
|
| 280 |
-
[*Note 5*: [[dcl.fct.default]] further describes the restrictions on
|
| 281 |
-
the use of names in default arguments. [[class.base.init]] further
|
| 282 |
-
describes the restrictions on the use of names in a
|
| 283 |
-
*ctor-initializer*. — *end note*]
|
| 284 |
-
|
| 285 |
-
During the lookup of a name used in the *constant-expression* of an
|
| 286 |
-
*enumerator-definition*, previously declared *enumerator*s of the
|
| 287 |
-
enumeration are visible and hide the names of entities declared in the
|
| 288 |
-
block, class, or namespace scopes containing the *enum-specifier*.
|
| 289 |
-
|
| 290 |
-
A name used in the definition of a `static` data member of class `X`
|
| 291 |
-
[[class.static.data]] (after the *qualified-id* of the static member) is
|
| 292 |
-
looked up as if the name was used in a member function of `X`.
|
| 293 |
-
|
| 294 |
-
[*Note 6*: [[class.static.data]] further describes the restrictions on
|
| 295 |
-
the use of names in the definition of a `static` data
|
| 296 |
-
member. — *end note*]
|
| 297 |
-
|
| 298 |
-
If a variable member of a namespace is defined outside of the scope of
|
| 299 |
-
its namespace then any name that appears in the definition of the member
|
| 300 |
-
(after the *declarator-id*) is looked up as if the definition of the
|
| 301 |
-
member occurred in its namespace.
|
| 302 |
-
|
| 303 |
-
[*Example 5*:
|
| 304 |
-
|
| 305 |
-
``` cpp
|
| 306 |
-
namespace N {
|
| 307 |
-
int i = 4;
|
| 308 |
-
extern int j;
|
| 309 |
-
}
|
| 310 |
-
|
| 311 |
-
int i = 2;
|
| 312 |
-
|
| 313 |
-
int N::j = i; // N::j == 4
|
| 314 |
-
```
|
| 315 |
-
|
| 316 |
-
— *end example*]
|
| 317 |
-
|
| 318 |
-
A name used in the handler for a *function-try-block* [[except.pre]] is
|
| 319 |
-
looked up as if the name was used in the outermost block of the function
|
| 320 |
-
definition. In particular, the function parameter names shall not be
|
| 321 |
-
redeclared in the *exception-declaration* nor in the outermost block of
|
| 322 |
-
a handler for the *function-try-block*. Names declared in the outermost
|
| 323 |
-
block of the function definition are not found when looked up in the
|
| 324 |
-
scope of a handler for the *function-try-block*.
|
| 325 |
-
|
| 326 |
-
[*Note 7*: But function parameter names are found. — *end note*]
|
| 327 |
-
|
| 328 |
-
[*Note 8*: The rules for name lookup in template definitions are
|
| 329 |
-
described in [[temp.res]]. — *end note*]
|
| 330 |
-
|
| 331 |
-
### Argument-dependent name lookup <a id="basic.lookup.argdep">[[basic.lookup.argdep]]</a>
|
| 332 |
-
|
| 333 |
-
When the *postfix-expression* in a function call [[expr.call]] is an
|
| 334 |
-
*unqualified-id*, other namespaces not considered during the usual
|
| 335 |
-
unqualified lookup [[basic.lookup.unqual]] may be searched, and in those
|
| 336 |
-
namespaces, namespace-scope friend function or function template
|
| 337 |
-
declarations [[class.friend]] not otherwise visible may be found. These
|
| 338 |
-
modifications to the search depend on the types of the arguments (and
|
| 339 |
-
for template template arguments, the namespace of the template
|
| 340 |
-
argument).
|
| 341 |
-
|
| 342 |
-
[*Example 1*:
|
| 343 |
-
|
| 344 |
-
``` cpp
|
| 345 |
-
namespace N {
|
| 346 |
-
struct S { };
|
| 347 |
-
void f(S);
|
| 348 |
-
}
|
| 349 |
-
|
| 350 |
-
void g() {
|
| 351 |
-
N::S s;
|
| 352 |
-
f(s); // OK: calls N::f
|
| 353 |
-
(f)(s); // error: N::f not considered; parentheses prevent argument-dependent lookup
|
| 354 |
-
}
|
| 355 |
-
```
|
| 356 |
-
|
| 357 |
-
— *end example*]
|
| 358 |
-
|
| 359 |
For each argument type `T` in the function call, there is a set of zero
|
| 360 |
-
or more *associated
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
types do not contribute to this set. The sets of namespaces and entities
|
| 366 |
-
are determined in the following way:
|
| 367 |
|
| 368 |
-
- If `T` is a fundamental type, its associated
|
| 369 |
-
entities are both empty.
|
| 370 |
- If `T` is a class type (including unions), its associated entities
|
| 371 |
are: the class itself; the class of which it is a member, if any; and
|
| 372 |
-
its direct and indirect base classes.
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
template
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
namespaces and entities are those associated with `U`.
|
| 388 |
-
- If `T` is a function type, its associated namespaces and entities are
|
| 389 |
-
those associated with the function parameter types and those
|
| 390 |
-
associated with the return type.
|
| 391 |
- If `T` is a pointer to a member function of a class `X`, its
|
| 392 |
-
associated
|
| 393 |
-
|
| 394 |
-
associated with `X`.
|
| 395 |
- If `T` is a pointer to a data member of class `X`, its associated
|
| 396 |
-
|
| 397 |
-
|
| 398 |
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
and return type. Additionally, if the aforementioned overload set is
|
| 407 |
-
named with a *template-id*, its associated entities and namespaces also
|
| 408 |
-
include those of its type *template-argument*s and its template
|
| 409 |
-
*template-argument*s.
|
| 410 |
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
|
|
|
|
|
|
| 414 |
|
| 415 |
-
- a
|
| 416 |
-
- a
|
| 417 |
-
or
|
| 418 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
[
|
| 426 |
-
types can include namespaces and entities already considered by the
|
| 427 |
-
ordinary unqualified lookup. — *end note*]
|
| 428 |
|
| 429 |
[*Example 2*:
|
| 430 |
|
| 431 |
-
``` cpp
|
| 432 |
-
namespace NS {
|
| 433 |
-
class T { };
|
| 434 |
-
void f(T);
|
| 435 |
-
void g(T, int);
|
| 436 |
-
}
|
| 437 |
-
NS::T parm;
|
| 438 |
-
void g(NS::T, float);
|
| 439 |
-
int main() {
|
| 440 |
-
f(parm); // OK: calls NS::f
|
| 441 |
-
extern void g(NS::T, float);
|
| 442 |
-
g(parm, 1); // OK: calls g(NS::T, float)
|
| 443 |
-
}
|
| 444 |
-
```
|
| 445 |
-
|
| 446 |
-
— *end example*]
|
| 447 |
-
|
| 448 |
-
When considering an associated namespace `N`, the lookup is the same as
|
| 449 |
-
the lookup performed when `N` is used as a qualifier [[namespace.qual]]
|
| 450 |
-
except that:
|
| 451 |
-
|
| 452 |
-
- Any *using-directive*s in `N` are ignored.
|
| 453 |
-
- All names except those of (possibly overloaded) functions and function
|
| 454 |
-
templates are ignored.
|
| 455 |
-
- Any namespace-scope friend functions or friend function templates
|
| 456 |
-
[[class.friend]] declared in classes with reachable definitions in the
|
| 457 |
-
set of associated entities are visible within their respective
|
| 458 |
-
namespaces even if they are not visible during an ordinary lookup
|
| 459 |
-
[[namespace.memdef]].
|
| 460 |
-
- Any exported declaration `D` in `N` declared within the purview of a
|
| 461 |
-
named module `M` [[module.interface]] is visible if there is an
|
| 462 |
-
associated entity attached to `M` with the same innermost enclosing
|
| 463 |
-
non-inline namespace as `D`.
|
| 464 |
-
- If the lookup is for a dependent name ([[temp.dep]],
|
| 465 |
-
[[temp.dep.candidate]]), any declaration `D` in `N` is visible if `D`
|
| 466 |
-
would be visible to qualified name lookup [[namespace.qual]] at any
|
| 467 |
-
point in the instantiation context [[module.context]] of the lookup,
|
| 468 |
-
unless `D` is declared in another translation unit, attached to the
|
| 469 |
-
global module, and is either discarded [[module.global.frag]] or has
|
| 470 |
-
internal linkage.
|
| 471 |
-
|
| 472 |
-
[*Example 3*:
|
| 473 |
-
|
| 474 |
Translation unit #1
|
| 475 |
|
| 476 |
``` cpp
|
| 477 |
export module M;
|
| 478 |
namespace R {
|
|
@@ -516,21 +609,42 @@ void test() {
|
|
| 516 |
}
|
| 517 |
```
|
| 518 |
|
| 519 |
— *end example*]
|
| 520 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
### Qualified name lookup <a id="basic.lookup.qual">[[basic.lookup.qual]]</a>
|
| 522 |
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
the program is ill-formed.
|
| 532 |
|
| 533 |
[*Example 1*:
|
| 534 |
|
| 535 |
``` cpp
|
| 536 |
class A {
|
|
@@ -540,70 +654,137 @@ public:
|
|
| 540 |
int main() {
|
| 541 |
int A;
|
| 542 |
A::n = 42; // OK
|
| 543 |
A b; // error: A does not name a type
|
| 544 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
```
|
| 546 |
|
| 547 |
— *end example*]
|
| 548 |
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
|
| 558 |
[*Example 2*:
|
| 559 |
|
|
|
|
|
|
|
| 560 |
``` cpp
|
| 561 |
-
|
| 562 |
-
class C {
|
| 563 |
-
class X { };
|
| 564 |
-
static const int number = 50;
|
| 565 |
-
static X arr[number];
|
| 566 |
-
};
|
| 567 |
-
X C::arr[number]; // error:
|
| 568 |
-
// equivalent to ::X C::arr[C::number];
|
| 569 |
-
// and not to C::X C::arr[C::number];
|
| 570 |
```
|
| 571 |
|
|
|
|
|
|
|
|
|
|
| 572 |
— *end example*]
|
| 573 |
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
``` bnf
|
| 588 |
-
nested-name-specifierₒₚₜ type-name '::' '~' type-name
|
| 589 |
-
```
|
| 590 |
-
|
| 591 |
-
the second *type-name* is looked up in the same scope as the first.
|
| 592 |
|
| 593 |
[*Example 3*:
|
| 594 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
``` cpp
|
| 596 |
struct C {
|
| 597 |
typedef int I;
|
| 598 |
};
|
| 599 |
typedef int I1, I2;
|
| 600 |
extern int* p;
|
| 601 |
extern int* q;
|
|
|
|
| 602 |
p->C::I::~I(); // I is looked up in the scope of C
|
| 603 |
-
q->I1::~I2();
|
| 604 |
-
|
| 605 |
struct A {
|
| 606 |
~A();
|
| 607 |
};
|
| 608 |
typedef A AB;
|
| 609 |
int main() {
|
|
@@ -612,55 +793,22 @@ int main() {
|
|
| 612 |
}
|
| 613 |
```
|
| 614 |
|
| 615 |
— *end example*]
|
| 616 |
|
| 617 |
-
[*Note 2*: [[basic.lookup.classref]] describes how name lookup
|
| 618 |
-
proceeds after the `.` and `->` operators. — *end note*]
|
| 619 |
-
|
| 620 |
#### Class members <a id="class.qual">[[class.qual]]</a>
|
| 621 |
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
scope of the class [[class.member.lookup]], except for the cases listed
|
| 625 |
-
below. The name shall represent one or more members of that class or of
|
| 626 |
-
one of its base classes [[class.derived]].
|
| 627 |
|
| 628 |
-
|
| 629 |
-
|
|
|
|
| 630 |
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
- a *conversion-type-id* of a *conversion-function-id* is looked up in
|
| 635 |
-
the same manner as a *conversion-type-id* in a class member access
|
| 636 |
-
(see [[basic.lookup.classref]]);
|
| 637 |
-
- the names in a *template-argument* of a *template-id* are looked up in
|
| 638 |
-
the context in which the entire *postfix-expression* occurs;
|
| 639 |
-
- the lookup for a name specified in a *using-declaration*
|
| 640 |
-
[[namespace.udecl]] also finds class or enumeration names hidden
|
| 641 |
-
within the same scope [[basic.scope.hiding]].
|
| 642 |
-
|
| 643 |
-
In a lookup in which function names are not ignored[^8] and the
|
| 644 |
-
*nested-name-specifier* nominates a class `C`:
|
| 645 |
-
|
| 646 |
-
- if the name specified after the *nested-name-specifier*, when looked
|
| 647 |
-
up in `C`, is the injected-class-name of `C` [[class.pre]], or
|
| 648 |
-
- in a *using-declarator* of a *using-declaration* [[namespace.udecl]]
|
| 649 |
-
that is a *member-declaration*, if the name specified after the
|
| 650 |
-
*nested-name-specifier* is the same as the *identifier* or the
|
| 651 |
-
*simple-template-id*’s *template-name* in the last component of the
|
| 652 |
-
*nested-name-specifier*,
|
| 653 |
-
|
| 654 |
-
the name is instead considered to name the constructor of class `C`.
|
| 655 |
-
|
| 656 |
-
[*Note 2*: For example, the constructor is not an acceptable lookup
|
| 657 |
-
result in an *elaborated-type-specifier* so the constructor would not be
|
| 658 |
-
used in place of the injected-class-name. — *end note*]
|
| 659 |
-
|
| 660 |
-
Such a constructor name shall be used only in the *declarator-id* of a
|
| 661 |
-
declaration that names a constructor or in a *using-declaration*.
|
| 662 |
|
| 663 |
[*Example 1*:
|
| 664 |
|
| 665 |
``` cpp
|
| 666 |
struct A { A(); };
|
|
@@ -674,39 +822,21 @@ A::A a; // error: A::A is not a type name
|
|
| 674 |
struct A::A a2; // object of type A
|
| 675 |
```
|
| 676 |
|
| 677 |
— *end example*]
|
| 678 |
|
| 679 |
-
A class member name hidden by a name in a nested declarative region or
|
| 680 |
-
by the name of a derived class member can still be found if qualified by
|
| 681 |
-
the name of its class followed by the `::` operator.
|
| 682 |
-
|
| 683 |
#### Namespace members <a id="namespace.qual">[[namespace.qual]]</a>
|
| 684 |
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
declarations of `m` in `X` and the inline namespace set of `X`
|
| 695 |
-
[[namespace.def]] whose potential scope [[basic.scope.namespace]] would
|
| 696 |
-
include the namespace in which `m` is declared at the location of the
|
| 697 |
-
*nested-name-specifier*. If S'(X, m) is not empty, S(X, m) is S'(X, m);
|
| 698 |
-
otherwise, S(X, m) is the union of S(Nᵢ, m) for all namespaces Nᵢ
|
| 699 |
-
nominated by *using-directive*s in `X` and its inline namespace set.
|
| 700 |
-
|
| 701 |
-
Given `X::m` (where `X` is a user-declared namespace), or given `::m`
|
| 702 |
-
(where X is the global namespace), if S(X, m) is the empty set, the
|
| 703 |
-
program is ill-formed. Otherwise, if S(X, m) has exactly one member, or
|
| 704 |
-
if the context of the reference is a *using-declaration*
|
| 705 |
-
[[namespace.udecl]], S(X, m) is the required set of declarations of `m`.
|
| 706 |
-
Otherwise if the use of `m` is not one that allows a unique declaration
|
| 707 |
-
to be chosen from S(X, m), the program is ill-formed.
|
| 708 |
|
| 709 |
[*Example 1*:
|
| 710 |
|
| 711 |
``` cpp
|
| 712 |
int x;
|
|
@@ -760,11 +890,11 @@ void h()
|
|
| 760 |
}
|
| 761 |
```
|
| 762 |
|
| 763 |
— *end example*]
|
| 764 |
|
| 765 |
-
[*Note
|
| 766 |
|
| 767 |
The same declaration found more than once is not an ambiguity (because
|
| 768 |
it is still a unique declaration).
|
| 769 |
|
| 770 |
[*Example 2*:
|
|
@@ -787,11 +917,11 @@ namespace BC {
|
|
| 787 |
using namespace C;
|
| 788 |
}
|
| 789 |
|
| 790 |
void f()
|
| 791 |
{
|
| 792 |
-
BC::a++; // OK
|
| 793 |
}
|
| 794 |
|
| 795 |
namespace D {
|
| 796 |
using A::a;
|
| 797 |
}
|
|
@@ -801,11 +931,11 @@ namespace BD {
|
|
| 801 |
using namespace D;
|
| 802 |
}
|
| 803 |
|
| 804 |
void g()
|
| 805 |
{
|
| 806 |
-
BD::a++; // OK
|
| 807 |
}
|
| 808 |
```
|
| 809 |
|
| 810 |
— *end example*]
|
| 811 |
|
|
@@ -830,26 +960,21 @@ namespace B {
|
|
| 830 |
using namespace A;
|
| 831 |
}
|
| 832 |
|
| 833 |
void f()
|
| 834 |
{
|
| 835 |
-
A::a++; // OK
|
| 836 |
-
B::a++; // OK
|
| 837 |
-
A::b++; // OK
|
| 838 |
-
B::b++; // OK
|
| 839 |
}
|
| 840 |
```
|
| 841 |
|
| 842 |
— *end example*]
|
| 843 |
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
introduces a class name or enumeration name and the other declarations
|
| 847 |
-
introduce either the same variable, the same enumerator, or a set of
|
| 848 |
-
functions, the non-type name hides the class or enumeration name if and
|
| 849 |
-
only if the declarations are from the same namespace; otherwise (the
|
| 850 |
-
declarations are from different namespaces), the program is ill-formed.
|
| 851 |
|
| 852 |
[*Example 4*:
|
| 853 |
|
| 854 |
``` cpp
|
| 855 |
namespace A {
|
|
@@ -870,221 +995,55 @@ namespace C {
|
|
| 870 |
}
|
| 871 |
```
|
| 872 |
|
| 873 |
— *end example*]
|
| 874 |
|
| 875 |
-
In a declaration for a namespace member in which the *declarator-id* is
|
| 876 |
-
a *qualified-id*, given that the *qualified-id* for the namespace member
|
| 877 |
-
has the form
|
| 878 |
-
|
| 879 |
-
``` bnf
|
| 880 |
-
nested-name-specifier unqualified-id
|
| 881 |
-
```
|
| 882 |
-
|
| 883 |
-
the *unqualified-id* shall name a member of the namespace designated by
|
| 884 |
-
the *nested-name-specifier* or of an element of the inline namespace set
|
| 885 |
-
[[namespace.def]] of that namespace.
|
| 886 |
-
|
| 887 |
-
[*Example 5*:
|
| 888 |
-
|
| 889 |
-
``` cpp
|
| 890 |
-
namespace A {
|
| 891 |
-
namespace B {
|
| 892 |
-
void f1(int);
|
| 893 |
-
}
|
| 894 |
-
using namespace B;
|
| 895 |
-
}
|
| 896 |
-
void A::f1(int){ } // error: f1 is not a member of A
|
| 897 |
-
```
|
| 898 |
-
|
| 899 |
-
— *end example*]
|
| 900 |
-
|
| 901 |
-
However, in such namespace member declarations, the
|
| 902 |
-
*nested-name-specifier* may rely on *using-directive*s to implicitly
|
| 903 |
-
provide the initial part of the *nested-name-specifier*.
|
| 904 |
-
|
| 905 |
-
[*Example 6*:
|
| 906 |
-
|
| 907 |
-
``` cpp
|
| 908 |
-
namespace A {
|
| 909 |
-
namespace B {
|
| 910 |
-
void f1(int);
|
| 911 |
-
}
|
| 912 |
-
}
|
| 913 |
-
|
| 914 |
-
namespace C {
|
| 915 |
-
namespace D {
|
| 916 |
-
void f1(int);
|
| 917 |
-
}
|
| 918 |
-
}
|
| 919 |
-
|
| 920 |
-
using namespace A;
|
| 921 |
-
using namespace C::D;
|
| 922 |
-
void B::f1(int){ } // OK, defines A::B::f1(int)
|
| 923 |
-
```
|
| 924 |
-
|
| 925 |
-
— *end example*]
|
| 926 |
-
|
| 927 |
### Elaborated type specifiers <a id="basic.lookup.elab">[[basic.lookup.elab]]</a>
|
| 928 |
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
ignoring any non-type names that have been declared. If the
|
| 943 |
-
*elaborated-type-specifier* is introduced by the `enum` keyword and this
|
| 944 |
-
lookup does not find a previously declared *type-name*, the
|
| 945 |
-
*elaborated-type-specifier* is ill-formed. If the
|
| 946 |
-
*elaborated-type-specifier* is introduced by the *class-key* and this
|
| 947 |
-
lookup does not find a previously declared *type-name*, or if the
|
| 948 |
-
*elaborated-type-specifier* appears in a declaration with the form:
|
| 949 |
-
|
| 950 |
-
``` bnf
|
| 951 |
-
class-key attribute-specifier-seqₒₚₜ identifier ';'
|
| 952 |
-
```
|
| 953 |
-
|
| 954 |
-
the *elaborated-type-specifier* is a declaration that introduces the
|
| 955 |
-
*class-name* as described in [[basic.scope.pdecl]].
|
| 956 |
-
|
| 957 |
-
If the *elaborated-type-specifier* has a *nested-name-specifier*,
|
| 958 |
-
qualified name lookup is performed, as described in
|
| 959 |
-
[[basic.lookup.qual]], but ignoring any non-type names that have been
|
| 960 |
-
declared. If the name lookup does not find a previously declared
|
| 961 |
-
*type-name*, the *elaborated-type-specifier* is ill-formed.
|
| 962 |
|
| 963 |
[*Example 1*:
|
| 964 |
|
| 965 |
``` cpp
|
| 966 |
struct Node {
|
| 967 |
-
struct Node* Next; // OK
|
| 968 |
-
struct Data* Data; // OK
|
| 969 |
};
|
| 970 |
|
| 971 |
struct Data {
|
| 972 |
-
struct Node* Node; // OK
|
| 973 |
friend struct ::Glob; // error: Glob is not declared, cannot introduce a qualified type[dcl.type.elab]
|
| 974 |
-
friend struct Glob; // OK
|
| 975 |
...
|
| 976 |
};
|
| 977 |
|
| 978 |
struct Base {
|
| 979 |
-
struct Data; // OK
|
| 980 |
-
struct ::Data* thatData; // OK
|
| 981 |
-
struct Base::Data* thisData; // OK
|
| 982 |
-
friend class ::Data; // OK
|
| 983 |
-
friend class Data; // OK
|
| 984 |
struct Data { ... }; // Defines nested Data
|
| 985 |
};
|
| 986 |
|
| 987 |
-
struct Data; // OK
|
| 988 |
struct ::Data; // error: cannot introduce a qualified type[dcl.type.elab]
|
| 989 |
struct Base::Data; // error: cannot introduce a qualified type[dcl.type.elab]
|
| 990 |
struct Base::Datum; // error: Datum undefined
|
| 991 |
-
struct Base::Data* pBase; // OK
|
| 992 |
-
```
|
| 993 |
-
|
| 994 |
-
— *end example*]
|
| 995 |
-
|
| 996 |
-
### Class member access <a id="basic.lookup.classref">[[basic.lookup.classref]]</a>
|
| 997 |
-
|
| 998 |
-
In a class member access expression [[expr.ref]], if the `.` or `->`
|
| 999 |
-
token is immediately followed by an *identifier* followed by a `<`, the
|
| 1000 |
-
identifier must be looked up to determine whether the `<` is the
|
| 1001 |
-
beginning of a template argument list [[temp.names]] or a less-than
|
| 1002 |
-
operator. The identifier is first looked up in the class of the object
|
| 1003 |
-
expression [[class.member.lookup]]. If the identifier is not found, it
|
| 1004 |
-
is then looked up in the context of the entire *postfix-expression* and
|
| 1005 |
-
shall name a template whose specializations are types.
|
| 1006 |
-
|
| 1007 |
-
If the *id-expression* in a class member access [[expr.ref]] is an
|
| 1008 |
-
*unqualified-id*, and the type of the object expression is of a class
|
| 1009 |
-
type `C`, the *unqualified-id* is looked up in the scope of class `C`
|
| 1010 |
-
[[class.member.lookup]].
|
| 1011 |
-
|
| 1012 |
-
If the *unqualified-id* is `~`*type-name*, the *type-name* is looked up
|
| 1013 |
-
in the context of the entire *postfix-expression*. If the type `T` of
|
| 1014 |
-
the object expression is of a class type `C`, the *type-name* is also
|
| 1015 |
-
looked up in the scope of class `C`. At least one of the lookups shall
|
| 1016 |
-
find a name that refers to cv `T`.
|
| 1017 |
-
|
| 1018 |
-
[*Example 1*:
|
| 1019 |
-
|
| 1020 |
-
``` cpp
|
| 1021 |
-
struct A { };
|
| 1022 |
-
|
| 1023 |
-
struct B {
|
| 1024 |
-
struct A { };
|
| 1025 |
-
void f(::A* a);
|
| 1026 |
-
};
|
| 1027 |
-
|
| 1028 |
-
void B::f(::A* a) {
|
| 1029 |
-
a->~A(); // OK: lookup in *a finds the injected-class-name
|
| 1030 |
-
}
|
| 1031 |
-
```
|
| 1032 |
-
|
| 1033 |
-
— *end example*]
|
| 1034 |
-
|
| 1035 |
-
If the *id-expression* in a class member access is a *qualified-id* of
|
| 1036 |
-
the form
|
| 1037 |
-
|
| 1038 |
-
``` cpp
|
| 1039 |
-
class-name-or-namespace-name::...
|
| 1040 |
-
```
|
| 1041 |
-
|
| 1042 |
-
the `class-name-or-namespace-name` following the `.` or `->` operator is
|
| 1043 |
-
first looked up in the class of the object expression
|
| 1044 |
-
[[class.member.lookup]] and the name, if found, is used. Otherwise it is
|
| 1045 |
-
looked up in the context of the entire *postfix-expression*.
|
| 1046 |
-
|
| 1047 |
-
[*Note 1*: See [[basic.lookup.qual]], which describes the lookup of a
|
| 1048 |
-
name before `::`, which will only find a type or namespace
|
| 1049 |
-
name. — *end note*]
|
| 1050 |
-
|
| 1051 |
-
If the *qualified-id* has the form
|
| 1052 |
-
|
| 1053 |
-
``` cpp
|
| 1054 |
-
::class-name-or-namespace-name::...
|
| 1055 |
-
```
|
| 1056 |
-
|
| 1057 |
-
the `class-name-or-namespace-name` is looked up in global scope as a
|
| 1058 |
-
*class-name* or *namespace-name*.
|
| 1059 |
-
|
| 1060 |
-
If the *nested-name-specifier* contains a *simple-template-id*
|
| 1061 |
-
[[temp.names]], the names in its *template-argument*s are looked up in
|
| 1062 |
-
the context in which the entire *postfix-expression* occurs.
|
| 1063 |
-
|
| 1064 |
-
If the *id-expression* is a *conversion-function-id*, its
|
| 1065 |
-
*conversion-type-id* is first looked up in the class of the object
|
| 1066 |
-
expression [[class.member.lookup]] and the name, if found, is used.
|
| 1067 |
-
Otherwise it is looked up in the context of the entire
|
| 1068 |
-
*postfix-expression*. In each of these lookups, only names that denote
|
| 1069 |
-
types or templates whose specializations are types are considered.
|
| 1070 |
-
|
| 1071 |
-
[*Example 2*:
|
| 1072 |
-
|
| 1073 |
-
``` cpp
|
| 1074 |
-
struct A { };
|
| 1075 |
-
namespace N {
|
| 1076 |
-
struct A {
|
| 1077 |
-
void g() { }
|
| 1078 |
-
template <class T> operator T();
|
| 1079 |
-
};
|
| 1080 |
-
}
|
| 1081 |
-
|
| 1082 |
-
int main() {
|
| 1083 |
-
N::A a;
|
| 1084 |
-
a.operator A(); // calls N::A::operator N::A
|
| 1085 |
-
}
|
| 1086 |
```
|
| 1087 |
|
| 1088 |
— *end example*]
|
| 1089 |
|
| 1090 |
### Using-directives and namespace aliases <a id="basic.lookup.udir">[[basic.lookup.udir]]</a>
|
|
|
|
| 1 |
## Name lookup <a id="basic.lookup">[[basic.lookup]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="basic.lookup.general">[[basic.lookup.general]]</a>
|
| 4 |
+
|
| 5 |
The name lookup rules apply uniformly to all names (including
|
| 6 |
*typedef-name*s [[dcl.typedef]], *namespace-name*s [[basic.namespace]],
|
| 7 |
and *class-name*s [[class.name]]) wherever the grammar allows such names
|
| 8 |
in the context discussed by a particular rule. Name lookup associates
|
| 9 |
the use of a name with a set of declarations [[basic.def]] of that name.
|
| 10 |
+
Unless otherwise specified, the program is ill-formed if no declarations
|
| 11 |
+
are found. If the declarations found by name lookup all denote functions
|
| 12 |
+
or function templates, the declarations are said to form an *overload
|
| 13 |
+
set*. Otherwise, if the declarations found by name lookup do not all
|
| 14 |
+
denote the same entity, they are *ambiguous* and the program is
|
| 15 |
+
ill-formed. Overload resolution [[over.match]], [[over.over]] takes
|
| 16 |
+
place after name lookup has succeeded. The access rules [[class.access]]
|
| 17 |
+
are considered only once name lookup and function overload resolution
|
| 18 |
+
(if applicable) have succeeded. Only after name lookup, function
|
| 19 |
+
overload resolution (if applicable) and access checking have succeeded
|
| 20 |
+
are the semantic properties introduced by the declarations used in
|
| 21 |
+
further processing.
|
| 22 |
+
|
| 23 |
+
A program point P is said to follow any declaration in the same
|
| 24 |
+
translation unit whose locus [[basic.scope.pdecl]] is before P.
|
| 25 |
+
|
| 26 |
+
[*Note 1*: The declaration might appear in a scope that does not
|
| 27 |
+
contain P. — *end note*]
|
| 28 |
+
|
| 29 |
+
A declaration X *precedes* a program point P in a translation unit L if
|
| 30 |
+
P follows X, X inhabits a class scope and is reachable from P, or else X
|
| 31 |
+
appears in a translation unit D and
|
| 32 |
+
|
| 33 |
+
- P follows a *module-import-declaration* or *module-declaration* that
|
| 34 |
+
imports D (directly or indirectly), and
|
| 35 |
+
- X appears after the *module-declaration* in D (if any) and before the
|
| 36 |
+
*private-module-fragment* in D (if any), and
|
| 37 |
+
- either X is exported or else D and L are part of the same module and X
|
| 38 |
+
does not inhabit a namespace with internal linkage or declare a name
|
| 39 |
+
with internal linkage. \[*Note 2*: Names declared by a
|
| 40 |
+
*using-declaration* have no linkage. — *end note*]
|
| 41 |
+
|
| 42 |
+
[*Note 3*:
|
| 43 |
+
|
| 44 |
+
A *module-import-declaration* imports both the named translation unit(s)
|
| 45 |
+
and any modules named by exported *module-import-declaration*s within
|
| 46 |
+
them, recursively.
|
| 47 |
+
|
| 48 |
+
[*Example 1*:
|
| 49 |
+
|
| 50 |
+
Translation unit #1
|
| 51 |
+
|
| 52 |
+
``` cpp
|
| 53 |
+
export module Q;
|
| 54 |
+
export int sq(int i) { return i*i; }
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Translation unit #2
|
| 58 |
+
|
| 59 |
+
``` cpp
|
| 60 |
+
export module R;
|
| 61 |
+
export import Q;
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
Translation unit #3
|
| 65 |
+
|
| 66 |
+
``` cpp
|
| 67 |
+
import R;
|
| 68 |
+
int main() { return sq(9); } // OK, sq from module Q
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
— *end example*]
|
| 72 |
+
|
| 73 |
+
— *end note*]
|
| 74 |
+
|
| 75 |
+
A *single search* in a scope S for a name N from a program point P finds
|
| 76 |
+
all declarations that precede P to which any name that is the same as N
|
| 77 |
+
[[basic.pre]] is bound in S. If any such declaration is a
|
| 78 |
+
*using-declarator* whose terminal name [[expr.prim.id.unqual]] is not
|
| 79 |
+
dependent [[temp.dep.type]], it is replaced by the declarations named by
|
| 80 |
+
the *using-declarator* [[namespace.udecl]].
|
| 81 |
+
|
| 82 |
+
In certain contexts, only certain kinds of declarations are included.
|
| 83 |
+
After any such restriction, any declarations of classes or enumerations
|
| 84 |
+
are discarded if any other declarations are found.
|
| 85 |
+
|
| 86 |
+
[*Note 4*: A type (but not a *typedef-name* or template) is therefore
|
| 87 |
+
hidden by any other entity in its scope. — *end note*]
|
| 88 |
+
|
| 89 |
+
However, if a lookup is *type-only*, only declarations of types and
|
| 90 |
+
templates whose specializations are types are considered; furthermore,
|
| 91 |
+
if declarations of a *typedef-name* and of the type to which it refers
|
| 92 |
+
are found, the declaration of the *typedef-name* is discarded instead of
|
| 93 |
+
the type declaration.
|
| 94 |
+
|
| 95 |
+
### Member name lookup <a id="class.member.lookup">[[class.member.lookup]]</a>
|
| 96 |
+
|
| 97 |
+
A *search* in a scope X for a name M from a program point P is a single
|
| 98 |
+
search in X for M from P unless X is the scope of a class or class
|
| 99 |
+
template T, in which case the following steps define the result of the
|
| 100 |
+
search.
|
| 101 |
+
|
| 102 |
+
[*Note 1*: The result differs only if M is a *conversion-function-id*
|
| 103 |
+
or if the single search would find nothing. — *end note*]
|
| 104 |
+
|
| 105 |
+
The *lookup set* for a name N in a class or class template C, called
|
| 106 |
+
S(N,C), consists of two component sets: the *declaration set*, a set of
|
| 107 |
+
members named N; and the *subobject set*, a set of subobjects where
|
| 108 |
+
declarations of these members were found (possibly via
|
| 109 |
+
*using-declaration*s). In the declaration set, type declarations
|
| 110 |
+
(including injected-class-names) are replaced by the types they
|
| 111 |
+
designate. S(N,C) is calculated as follows:
|
| 112 |
+
|
| 113 |
+
The declaration set is the result of a single search in the scope of C
|
| 114 |
+
for N from immediately after the *class-specifier* of C if P is in a
|
| 115 |
+
complete-class context of C or from P otherwise. If the resulting
|
| 116 |
+
declaration set is not empty, the subobject set contains C itself, and
|
| 117 |
+
calculation is complete.
|
| 118 |
+
|
| 119 |
+
Otherwise (i.e., C does not contain a declaration of N or the resulting
|
| 120 |
+
declaration set is empty), S(N,C) is initially empty. Calculate the
|
| 121 |
+
lookup set for N in each direct non-dependent [[temp.dep.type]] base
|
| 122 |
+
class subobject Bᵢ, and merge each such lookup set S(N,Bᵢ) in turn into
|
| 123 |
+
S(N,C).
|
| 124 |
+
|
| 125 |
+
[*Note 2*: If C is incomplete, only base classes whose *base-specifier*
|
| 126 |
+
appears before P are considered. If C is an instantiated class, its base
|
| 127 |
+
classes are not dependent. — *end note*]
|
| 128 |
+
|
| 129 |
+
The following steps define the result of merging lookup set S(N,Bᵢ) into
|
| 130 |
+
the intermediate S(N,C):
|
| 131 |
+
|
| 132 |
+
- If each of the subobject members of S(N,Bᵢ) is a base class subobject
|
| 133 |
+
of at least one of the subobject members of S(N,C), or if S(N,Bᵢ) is
|
| 134 |
+
empty, S(N,C) is unchanged and the merge is complete. Conversely, if
|
| 135 |
+
each of the subobject members of S(N,C) is a base class subobject of
|
| 136 |
+
at least one of the subobject members of S(N,Bᵢ), or if S(N,C) is
|
| 137 |
+
empty, the new S(N,C) is a copy of S(N,Bᵢ).
|
| 138 |
+
- Otherwise, if the declaration sets of S(N,Bᵢ) and S(N,C) differ, the
|
| 139 |
+
merge is ambiguous: the new S(N,C) is a lookup set with an invalid
|
| 140 |
+
declaration set and the union of the subobject sets. In subsequent
|
| 141 |
+
merges, an invalid declaration set is considered different from any
|
| 142 |
+
other.
|
| 143 |
+
- Otherwise, the new S(N,C) is a lookup set with the shared set of
|
| 144 |
+
declarations and the union of the subobject sets.
|
| 145 |
+
|
| 146 |
+
The result of the search is the declaration set of S(M,T). If it is an
|
| 147 |
+
invalid set, the program is ill-formed. If it differs from the result of
|
| 148 |
+
a search in T for M in a complete-class context [[class.mem]] of T, the
|
| 149 |
+
program is ill-formed, no diagnostic required.
|
| 150 |
+
|
| 151 |
+
[*Example 1*:
|
| 152 |
+
|
| 153 |
+
``` cpp
|
| 154 |
+
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
|
| 155 |
+
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
|
| 156 |
+
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
|
| 157 |
+
struct D: public virtual C { }; // S(x,D) = S(x,C)
|
| 158 |
+
struct E: public virtual C { char x; }; // S(x,E) = { { E::x }, { E } }
|
| 159 |
+
struct F: public D, public E { }; // S(x,F) = S(x,E)
|
| 160 |
+
int main() {
|
| 161 |
+
F f;
|
| 162 |
+
f.x = 0; // OK, lookup finds E::x
|
| 163 |
+
}
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
S(`x`,`F`) is unambiguous because the `A` and `B` base class subobjects
|
| 167 |
+
of `D` are also base class subobjects of `E`, so S(`x`,`D`) is discarded
|
| 168 |
+
in the first merge step.
|
| 169 |
+
|
| 170 |
+
— *end example*]
|
| 171 |
+
|
| 172 |
+
If M is a non-dependent *conversion-function-id*, conversion function
|
| 173 |
+
templates that are members of T are considered. For each such template
|
| 174 |
+
F, the lookup set S(t,T) is constructed, considering a function template
|
| 175 |
+
declaration to have the name t only if it corresponds to a declaration
|
| 176 |
+
of F [[basic.scope.scope]]. The members of the declaration set of each
|
| 177 |
+
such lookup set, which shall not be an invalid set, are included in the
|
| 178 |
+
result.
|
| 179 |
+
|
| 180 |
+
[*Note 3*: Overload resolution will discard those that cannot convert
|
| 181 |
+
to the type specified by M [[temp.over]]. — *end note*]
|
| 182 |
+
|
| 183 |
+
[*Note 4*: A static member, a nested type or an enumerator defined in a
|
| 184 |
+
base class `T` can unambiguously be found even if an object has more
|
| 185 |
+
than one base class subobject of type `T`. Two base class subobjects
|
| 186 |
+
share the non-static member subobjects of their common virtual base
|
| 187 |
+
classes. — *end note*]
|
| 188 |
+
|
| 189 |
+
[*Example 2*:
|
| 190 |
+
|
| 191 |
+
``` cpp
|
| 192 |
+
struct V {
|
| 193 |
+
int v;
|
| 194 |
+
};
|
| 195 |
+
struct A {
|
| 196 |
+
int a;
|
| 197 |
+
static int s;
|
| 198 |
+
enum { e };
|
| 199 |
+
};
|
| 200 |
+
struct B : A, virtual V { };
|
| 201 |
+
struct C : A, virtual V { };
|
| 202 |
+
struct D : B, C { };
|
| 203 |
+
|
| 204 |
+
void f(D* pd) {
|
| 205 |
+
pd->v++; // OK, only one v (virtual)
|
| 206 |
+
pd->s++; // OK, only one s (static)
|
| 207 |
+
int i = pd->e; // OK, only one e (enumerator)
|
| 208 |
+
pd->a++; // error: ambiguous: two a{s} in D
|
| 209 |
+
}
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
— *end example*]
|
| 213 |
+
|
| 214 |
+
[*Note 5*: When virtual base classes are used, a hidden declaration
|
| 215 |
+
can be reached along a path through the subobject lattice that does not
|
| 216 |
+
pass through the hiding declaration. This is not an ambiguity. The
|
| 217 |
+
identical use with non-virtual base classes is an ambiguity; in that
|
| 218 |
+
case there is no unique instance of the name that hides all the
|
| 219 |
+
others. — *end note*]
|
| 220 |
+
|
| 221 |
+
[*Example 3*:
|
| 222 |
+
|
| 223 |
+
``` cpp
|
| 224 |
+
struct V { int f(); int x; };
|
| 225 |
+
struct W { int g(); int y; };
|
| 226 |
+
struct B : virtual V, W {
|
| 227 |
+
int f(); int x;
|
| 228 |
+
int g(); int y;
|
| 229 |
+
};
|
| 230 |
+
struct C : virtual V, W { };
|
| 231 |
+
|
| 232 |
+
struct D : B, C { void glorp(); };
|
| 233 |
+
```
|
| 234 |
+
|
| 235 |
+
<a id="fig:class.lookup"></a>
|
| 236 |
+
|
| 237 |
+
![Name lookup \[fig:class.lookup\]](images/figname.svg)
|
| 238 |
+
|
| 239 |
+
As illustrated in Figure [[fig:class.lookup]], the names declared in
|
| 240 |
+
`V` and the left-hand instance of `W` are hidden by those in `B`, but
|
| 241 |
+
the names declared in the right-hand instance of `W` are not hidden at
|
| 242 |
+
all.
|
| 243 |
+
|
| 244 |
+
``` cpp
|
| 245 |
+
void D::glorp() {
|
| 246 |
+
x++; // OK, B::x hides V::x
|
| 247 |
+
f(); // OK, B::f() hides V::f()
|
| 248 |
+
y++; // error: B::y and C's W::y
|
| 249 |
+
g(); // error: B::g() and C's W::g()
|
| 250 |
+
}
|
| 251 |
+
```
|
| 252 |
+
|
| 253 |
+
— *end example*]
|
| 254 |
+
|
| 255 |
+
An explicit or implicit conversion from a pointer to or an expression
|
| 256 |
+
designating an object of a derived class to a pointer or reference to
|
| 257 |
+
one of its base classes shall unambiguously refer to a unique object
|
| 258 |
+
representing the base class.
|
| 259 |
+
|
| 260 |
+
[*Example 4*:
|
| 261 |
+
|
| 262 |
+
``` cpp
|
| 263 |
+
struct V { };
|
| 264 |
+
struct A { };
|
| 265 |
+
struct B : A, virtual V { };
|
| 266 |
+
struct C : A, virtual V { };
|
| 267 |
+
struct D : B, C { };
|
| 268 |
+
|
| 269 |
+
void g() {
|
| 270 |
+
D d;
|
| 271 |
+
B* pb = &d;
|
| 272 |
+
A* pa = &d; // error: ambiguous: C's A or B's A?
|
| 273 |
+
V* pv = &d; // OK, only one V subobject
|
| 274 |
+
}
|
| 275 |
+
```
|
| 276 |
+
|
| 277 |
+
— *end example*]
|
| 278 |
+
|
| 279 |
+
[*Note 6*: Even if the result of name lookup is unambiguous, use of a
|
| 280 |
+
name found in multiple subobjects might still be ambiguous
|
| 281 |
+
[[conv.mem]], [[expr.ref]], [[class.access.base]]. — *end note*]
|
| 282 |
+
|
| 283 |
+
[*Example 5*:
|
| 284 |
+
|
| 285 |
+
``` cpp
|
| 286 |
+
struct B1 {
|
| 287 |
+
void f();
|
| 288 |
+
static void f(int);
|
| 289 |
+
int i;
|
| 290 |
+
};
|
| 291 |
+
struct B2 {
|
| 292 |
+
void f(double);
|
| 293 |
+
};
|
| 294 |
+
struct I1: B1 { };
|
| 295 |
+
struct I2: B1 { };
|
| 296 |
+
|
| 297 |
+
struct D: I1, I2, B2 {
|
| 298 |
+
using B1::f;
|
| 299 |
+
using B2::f;
|
| 300 |
+
void g() {
|
| 301 |
+
f(); // Ambiguous conversion of this
|
| 302 |
+
f(0); // Unambiguous (static)
|
| 303 |
+
f(0.0); // Unambiguous (only one B2)
|
| 304 |
+
int B1::* mpB1 = &D::i; // Unambiguous
|
| 305 |
+
int D::* mpD = &D::i; // Ambiguous conversion
|
| 306 |
+
}
|
| 307 |
+
};
|
| 308 |
+
```
|
| 309 |
+
|
| 310 |
+
— *end example*]
|
| 311 |
|
| 312 |
### Unqualified name lookup <a id="basic.lookup.unqual">[[basic.lookup.unqual]]</a>
|
| 313 |
|
| 314 |
+
A *using-directive* is *active* in a scope S at a program point P if it
|
| 315 |
+
precedes P and inhabits either S or the scope of a namespace nominated
|
| 316 |
+
by a *using-directive* that is active in S at P.
|
| 317 |
+
|
| 318 |
+
An *unqualified search* in a scope S from a program point P includes the
|
| 319 |
+
results of searches from P in
|
| 320 |
+
|
| 321 |
+
- S, and
|
| 322 |
+
- for any scope U that contains P and is or is contained by S, each
|
| 323 |
+
namespace contained by S that is nominated by a *using-directive* that
|
| 324 |
+
is active in U at P.
|
| 325 |
+
|
| 326 |
+
If no declarations are found, the results of the unqualified search are
|
| 327 |
+
the results of an unqualified search in the parent scope of S, if any,
|
| 328 |
+
from P.
|
| 329 |
+
|
| 330 |
+
[*Note 1*: When a class scope is searched, the scopes of its base
|
| 331 |
+
classes are also searched [[class.member.lookup]]. If it inherits from a
|
| 332 |
+
single base, it is as if the scope of the base immediately contains the
|
| 333 |
+
scope of the derived class. Template parameter scopes that are
|
| 334 |
+
associated with one scope in the chain of parents are also considered
|
| 335 |
+
[[temp.local]]. — *end note*]
|
| 336 |
+
|
| 337 |
+
*Unqualified name lookup* from a program point performs an unqualified
|
| 338 |
+
search in its immediate scope.
|
| 339 |
+
|
| 340 |
+
An *unqualified name* is a name that does not immediately follow a
|
| 341 |
+
*nested-name-specifier* or the `.` or `->` in a class member access
|
| 342 |
+
expression [[expr.ref]], possibly after a `template` keyword or `~`.
|
| 343 |
+
Unless otherwise specified, such a name undergoes unqualified name
|
| 344 |
+
lookup from the point where it appears.
|
| 345 |
+
|
| 346 |
+
An unqualified name that is a component name [[expr.prim.id.unqual]] of
|
| 347 |
+
a *type-specifier* or *ptr-operator* of a *conversion-type-id* is looked
|
| 348 |
+
up in the same fashion as the *conversion-function-id* in which it
|
| 349 |
+
appears. If that lookup finds nothing, it undergoes unqualified name
|
| 350 |
+
lookup; in each case, only names that denote types or templates whose
|
| 351 |
+
specializations are types are considered.
|
| 352 |
+
|
| 353 |
+
[*Example 1*:
|
| 354 |
+
|
| 355 |
+
``` cpp
|
| 356 |
+
struct T1 { struct U { int i; }; };
|
| 357 |
+
struct T2 { };
|
| 358 |
+
struct U1 {};
|
| 359 |
+
struct U2 {};
|
| 360 |
+
|
| 361 |
+
struct B {
|
| 362 |
+
using T = T1;
|
| 363 |
+
using U = U1;
|
| 364 |
+
operator U1 T1::*();
|
| 365 |
+
operator U1 T2::*();
|
| 366 |
+
operator U2 T1::*();
|
| 367 |
+
operator U2 T2::*();
|
| 368 |
+
};
|
| 369 |
+
|
| 370 |
+
template<class X, class T>
|
| 371 |
+
int g() {
|
| 372 |
+
using U = U2;
|
| 373 |
+
X().operator U T::*(); // #1, searches for T in the scope of X first
|
| 374 |
+
X().operator U decltype(T())::*(); // #2
|
| 375 |
+
return 0;
|
| 376 |
+
}
|
| 377 |
+
int x = g<B, T2>(); // #1 calls B::operator U1 T1::*
|
| 378 |
+
// #2 calls B::operator U1 T2::*
|
| 379 |
+
```
|
| 380 |
+
|
| 381 |
+
— *end example*]
|
| 382 |
+
|
| 383 |
+
In a friend declaration *declarator* whose *declarator-id* is a
|
| 384 |
+
*qualified-id* whose lookup context [[basic.lookup.qual]] is a class or
|
| 385 |
+
namespace S, lookup for an unqualified name that appears after the
|
| 386 |
+
*declarator-id* performs a search in the scope associated with S. If
|
| 387 |
+
that lookup finds nothing, it undergoes unqualified name lookup.
|
| 388 |
+
|
| 389 |
+
[*Example 2*:
|
| 390 |
+
|
| 391 |
+
``` cpp
|
| 392 |
+
using I = int;
|
| 393 |
+
using D = double;
|
| 394 |
+
namespace A {
|
| 395 |
+
inline namespace N {using C = char; }
|
| 396 |
+
using F = float;
|
| 397 |
+
void f(I);
|
| 398 |
+
void f(D);
|
| 399 |
+
void f(C);
|
| 400 |
+
void f(F);
|
| 401 |
+
}
|
| 402 |
+
struct X0 {using F = float; };
|
| 403 |
+
struct W {
|
| 404 |
+
using D = void;
|
| 405 |
+
struct X : X0 {
|
| 406 |
+
void g(I);
|
| 407 |
+
void g(::D);
|
| 408 |
+
void g(F);
|
| 409 |
+
};
|
| 410 |
+
};
|
| 411 |
+
namespace B {
|
| 412 |
+
typedef short I, F;
|
| 413 |
+
class Y {
|
| 414 |
+
friend void A::f(I); // error: no void A::f(short)
|
| 415 |
+
friend void A::f(D); // OK
|
| 416 |
+
friend void A::f(C); // error: A::N::C not found
|
| 417 |
+
friend void A::f(F); // OK
|
| 418 |
+
friend void W::X::g(I); // error: no void X::g(short)
|
| 419 |
+
friend void W::X::g(D); // OK
|
| 420 |
+
friend void W::X::g(F); // OK
|
| 421 |
+
};
|
| 422 |
+
}
|
| 423 |
+
```
|
| 424 |
+
|
| 425 |
+
— *end example*]
|
| 426 |
+
|
| 427 |
+
### Argument-dependent name lookup <a id="basic.lookup.argdep">[[basic.lookup.argdep]]</a>
|
| 428 |
+
|
| 429 |
+
When the *postfix-expression* in a function call [[expr.call]] is an
|
| 430 |
+
*unqualified-id*, and unqualified lookup [[basic.lookup.unqual]] for the
|
| 431 |
+
name in the *unqualified-id* does not find any
|
| 432 |
+
|
| 433 |
+
- declaration of a class member, or
|
| 434 |
+
- function declaration inhabiting a block scope, or
|
| 435 |
+
- declaration not of a function or function template
|
| 436 |
+
|
| 437 |
+
then lookup for the name also includes the result of
|
| 438 |
+
*argument-dependent lookup* in a set of associated namespaces that
|
| 439 |
+
depends on the types of the arguments (and for template template
|
| 440 |
+
arguments, the namespace of the template argument), as specified below.
|
| 441 |
+
|
| 442 |
+
[*Example 1*:
|
| 443 |
+
|
| 444 |
+
``` cpp
|
| 445 |
+
namespace N {
|
| 446 |
+
struct S { };
|
| 447 |
+
void f(S);
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
void g() {
|
| 451 |
+
N::S s;
|
| 452 |
+
f(s); // OK, calls N::f
|
| 453 |
+
(f)(s); // error: N::f not considered; parentheses prevent argument-dependent lookup
|
| 454 |
+
}
|
| 455 |
+
```
|
| 456 |
+
|
| 457 |
+
— *end example*]
|
| 458 |
|
| 459 |
[*Note 1*:
|
| 460 |
|
| 461 |
For purposes of determining (during parsing) whether an expression is a
|
| 462 |
*postfix-expression* for a function call, the usual name lookup rules
|
|
|
|
| 472 |
template <class T> int f(T);
|
| 473 |
template <class T> int g(T);
|
| 474 |
template <class T> int h(T);
|
| 475 |
}
|
| 476 |
|
| 477 |
+
int x = f<N::A>(N::A()); // OK, lookup of f finds nothing, f treated as template name
|
| 478 |
+
int y = g<N::A>(N::A()); // OK, lookup of g finds a function, g treated as template name
|
| 479 |
int z = h<N::A>(N::A()); // error: h< does not begin a template-id
|
| 480 |
```
|
| 481 |
|
| 482 |
+
The rules have no effect on the syntactic interpretation of an
|
| 483 |
+
expression. For example,
|
| 484 |
|
| 485 |
``` cpp
|
| 486 |
typedef int f;
|
| 487 |
namespace N {
|
| 488 |
struct A {
|
|
|
|
| 493 |
}
|
| 494 |
};
|
| 495 |
}
|
| 496 |
```
|
| 497 |
|
| 498 |
+
Because the expression is not a function call, argument-dependent name
|
| 499 |
+
lookup does not apply and the friend function `f` is not found.
|
|
|
|
| 500 |
|
| 501 |
— *end note*]
|
| 502 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
For each argument type `T` in the function call, there is a set of zero
|
| 504 |
+
or more *associated entities* to be considered. The set of entities is
|
| 505 |
+
determined entirely by the types of the function arguments (and any
|
| 506 |
+
template template arguments). Any *typedef-name*s and
|
| 507 |
+
*using-declaration*s used to specify the types do not contribute to this
|
| 508 |
+
set. The set of entities is determined in the following way:
|
|
|
|
|
|
|
| 509 |
|
| 510 |
+
- If `T` is a fundamental type, its associated set of entities is empty.
|
|
|
|
| 511 |
- If `T` is a class type (including unions), its associated entities
|
| 512 |
are: the class itself; the class of which it is a member, if any; and
|
| 513 |
+
its direct and indirect base classes. Furthermore, if `T` is a class
|
| 514 |
+
template specialization, its associated entities also include: the
|
| 515 |
+
entities associated with the types of the template arguments provided
|
| 516 |
+
for template type parameters; the templates used as template template
|
| 517 |
+
arguments; and the classes of which any member templates used as
|
| 518 |
+
template template arguments are members. \[*Note 2*: Non-type template
|
| 519 |
+
arguments do not contribute to the set of associated
|
| 520 |
+
entities. — *end note*]
|
| 521 |
+
- If `T` is an enumeration type, its associated entities are `T` and, if
|
| 522 |
+
it is a class member, the member’s class.
|
| 523 |
+
- If `T` is a pointer to `U` or an array of `U`, its associated entities
|
| 524 |
+
are those associated with `U`.
|
| 525 |
+
- If `T` is a function type, its associated entities are those
|
| 526 |
+
associated with the function parameter types and those associated with
|
| 527 |
+
the return type.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
- If `T` is a pointer to a member function of a class `X`, its
|
| 529 |
+
associated entities are those associated with the function parameter
|
| 530 |
+
types and return type, together with those associated with `X`.
|
|
|
|
| 531 |
- If `T` is a pointer to a data member of class `X`, its associated
|
| 532 |
+
entities are those associated with the member type together with those
|
| 533 |
+
associated with `X`.
|
| 534 |
|
| 535 |
+
In addition, if the argument is an overload set or the address of such a
|
| 536 |
+
set, its associated entities are the union of those associated with each
|
| 537 |
+
of the members of the set, i.e., the entities associated with its
|
| 538 |
+
parameter types and return type. Additionally, if the aforementioned
|
| 539 |
+
overload set is named with a *template-id*, its associated entities also
|
| 540 |
+
include its template *template-argument*s and those associated with its
|
| 541 |
+
type *template-argument*s.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 542 |
|
| 543 |
+
The *associated namespaces* for a call are the innermost enclosing
|
| 544 |
+
non-inline namespaces for its associated entities as well as every
|
| 545 |
+
element of the inline namespace set [[namespace.def]] of those
|
| 546 |
+
namespaces. Argument-dependent lookup finds all declarations of
|
| 547 |
+
functions and function templates that
|
| 548 |
|
| 549 |
+
- are found by a search of any associated namespace, or
|
| 550 |
+
- are declared as a friend [[class.friend]] of any class with a
|
| 551 |
+
reachable definition in the set of associated entities, or
|
| 552 |
+
- are exported, are attached to a named module `M` [[module.interface]],
|
| 553 |
+
do not appear in the translation unit containing the point of the
|
| 554 |
+
lookup, and have the same innermost enclosing non-inline namespace
|
| 555 |
+
scope as a declaration of an associated entity attached to `M`
|
| 556 |
+
[[basic.link]].
|
| 557 |
|
| 558 |
+
If the lookup is for a dependent name
|
| 559 |
+
[[temp.dep]], [[temp.dep.candidate]], the above lookup is also performed
|
| 560 |
+
from each point in the instantiation context [[module.context]] of the
|
| 561 |
+
lookup, additionally ignoring any declaration that appears in another
|
| 562 |
+
translation unit, is attached to the global module, and is either
|
| 563 |
+
discarded [[module.global.frag]] or has internal linkage.
|
|
|
|
|
|
|
| 564 |
|
| 565 |
[*Example 2*:
|
| 566 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 567 |
Translation unit #1
|
| 568 |
|
| 569 |
``` cpp
|
| 570 |
export module M;
|
| 571 |
namespace R {
|
|
|
|
| 609 |
}
|
| 610 |
```
|
| 611 |
|
| 612 |
— *end example*]
|
| 613 |
|
| 614 |
+
[*Note 3*: The associated namespace can include namespaces already
|
| 615 |
+
considered by ordinary unqualified lookup. — *end note*]
|
| 616 |
+
|
| 617 |
+
[*Example 3*:
|
| 618 |
+
|
| 619 |
+
``` cpp
|
| 620 |
+
namespace NS {
|
| 621 |
+
class T { };
|
| 622 |
+
void f(T);
|
| 623 |
+
void g(T, int);
|
| 624 |
+
}
|
| 625 |
+
NS::T parm;
|
| 626 |
+
void g(NS::T, float);
|
| 627 |
+
int main() {
|
| 628 |
+
f(parm); // OK, calls NS::f
|
| 629 |
+
extern void g(NS::T, float);
|
| 630 |
+
g(parm, 1); // OK, calls g(NS::T, float)
|
| 631 |
+
}
|
| 632 |
+
```
|
| 633 |
+
|
| 634 |
+
— *end example*]
|
| 635 |
+
|
| 636 |
### Qualified name lookup <a id="basic.lookup.qual">[[basic.lookup.qual]]</a>
|
| 637 |
|
| 638 |
+
#### General <a id="basic.lookup.qual.general">[[basic.lookup.qual.general]]</a>
|
| 639 |
+
|
| 640 |
+
Lookup of an *identifier* followed by a `::` scope resolution operator
|
| 641 |
+
considers only namespaces, types, and templates whose specializations
|
| 642 |
+
are types. If a name, *template-id*, or *decltype-specifier* is followed
|
| 643 |
+
by a `::`, it shall designate a namespace, class, enumeration, or
|
| 644 |
+
dependent type, and the `::` is never interpreted as a complete
|
| 645 |
+
*nested-name-specifier*.
|
|
|
|
| 646 |
|
| 647 |
[*Example 1*:
|
| 648 |
|
| 649 |
``` cpp
|
| 650 |
class A {
|
|
|
|
| 654 |
int main() {
|
| 655 |
int A;
|
| 656 |
A::n = 42; // OK
|
| 657 |
A b; // error: A does not name a type
|
| 658 |
}
|
| 659 |
+
template<int> struct B : A {};
|
| 660 |
+
namespace N {
|
| 661 |
+
template<int> void B();
|
| 662 |
+
int f() {
|
| 663 |
+
return B<0>::n; // error: N::B<0> is not a type
|
| 664 |
+
}
|
| 665 |
+
}
|
| 666 |
```
|
| 667 |
|
| 668 |
— *end example*]
|
| 669 |
|
| 670 |
+
A member-qualified name is the (unique) component name
|
| 671 |
+
[[expr.prim.id.unqual]], if any, of
|
| 672 |
+
|
| 673 |
+
- an *unqualified-id* or
|
| 674 |
+
- a *nested-name-specifier* of the form *type-name* `::` or
|
| 675 |
+
*namespace-name* `::`
|
| 676 |
+
|
| 677 |
+
in the *id-expression* of a class member access expression [[expr.ref]].
|
| 678 |
+
A *qualified name* is
|
| 679 |
+
|
| 680 |
+
- a member-qualified name or
|
| 681 |
+
- the terminal name of
|
| 682 |
+
- a *qualified-id*,
|
| 683 |
+
- a *using-declarator*,
|
| 684 |
+
- a *typename-specifier*,
|
| 685 |
+
- a *qualified-namespace-specifier*, or
|
| 686 |
+
- a *nested-name-specifier*, *elaborated-type-specifier*, or
|
| 687 |
+
*class-or-decltype* that has a *nested-name-specifier*
|
| 688 |
+
[[expr.prim.id.qual]].
|
| 689 |
+
|
| 690 |
+
The *lookup context* of a member-qualified name is the type of its
|
| 691 |
+
associated object expression (considered dependent if the object
|
| 692 |
+
expression is type-dependent). The lookup context of any other qualified
|
| 693 |
+
name is the type, template, or namespace nominated by the preceding
|
| 694 |
+
*nested-name-specifier*.
|
| 695 |
+
|
| 696 |
+
[*Note 1*: When parsing a class member access, the name following the
|
| 697 |
+
`->` or `.` is a qualified name even though it is not yet known of which
|
| 698 |
+
kind. — *end note*]
|
| 699 |
|
| 700 |
[*Example 2*:
|
| 701 |
|
| 702 |
+
In
|
| 703 |
+
|
| 704 |
``` cpp
|
| 705 |
+
N::C::m.Base::f()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
```
|
| 707 |
|
| 708 |
+
`Base` is a member-qualified name; the other qualified names are `C`,
|
| 709 |
+
`m`, and `f`.
|
| 710 |
+
|
| 711 |
— *end example*]
|
| 712 |
|
| 713 |
+
*Qualified name lookup* in a class, namespace, or enumeration performs a
|
| 714 |
+
search of the scope associated with it [[class.member.lookup]] except as
|
| 715 |
+
specified below. Unless otherwise specified, a qualified name undergoes
|
| 716 |
+
qualified name lookup in its lookup context from the point where it
|
| 717 |
+
appears unless the lookup context either is dependent and is not the
|
| 718 |
+
current instantiation [[temp.dep.type]] or is not a class or class
|
| 719 |
+
template. If nothing is found by qualified lookup for a member-qualified
|
| 720 |
+
name that is the terminal name [[expr.prim.id.unqual]] of a
|
| 721 |
+
*nested-name-specifier* and is not dependent, it undergoes unqualified
|
| 722 |
+
lookup.
|
| 723 |
+
|
| 724 |
+
[*Note 2*: During lookup for a template specialization, no names are
|
| 725 |
+
dependent. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 726 |
|
| 727 |
[*Example 3*:
|
| 728 |
|
| 729 |
+
``` cpp
|
| 730 |
+
int f();
|
| 731 |
+
struct A {
|
| 732 |
+
int B, C;
|
| 733 |
+
template<int> using D = void;
|
| 734 |
+
using T = void;
|
| 735 |
+
void f();
|
| 736 |
+
};
|
| 737 |
+
using B = A;
|
| 738 |
+
template<int> using C = A;
|
| 739 |
+
template<int> using D = A;
|
| 740 |
+
template<int> using X = A;
|
| 741 |
+
|
| 742 |
+
template<class T>
|
| 743 |
+
void g(T *p) { // as instantiated for g<A>:
|
| 744 |
+
p->X<0>::f(); // error: A::X not found in ((p->X) < 0) > ::f()
|
| 745 |
+
p->template X<0>::f(); // OK, ::X found in definition context
|
| 746 |
+
p->B::f(); // OK, non-type A::B ignored
|
| 747 |
+
p->template C<0>::f(); // error: A::C is not a template
|
| 748 |
+
p->template D<0>::f(); // error: A::D<0> is not a class type
|
| 749 |
+
p->T::f(); // error: A::T is not a class type
|
| 750 |
+
}
|
| 751 |
+
template void g(A*);
|
| 752 |
+
```
|
| 753 |
+
|
| 754 |
+
— *end example*]
|
| 755 |
+
|
| 756 |
+
If a qualified name Q follows a `~`:
|
| 757 |
+
|
| 758 |
+
- If Q is a member-qualified name, it undergoes unqualified lookup as
|
| 759 |
+
well as qualified lookup.
|
| 760 |
+
- Otherwise, its *nested-name-specifier* N shall nominate a type. If N
|
| 761 |
+
has another *nested-name-specifier* S, Q is looked up as if its lookup
|
| 762 |
+
context were that nominated by S.
|
| 763 |
+
- Otherwise, if the terminal name of N is a member-qualified name M, Q
|
| 764 |
+
is looked up as if `\~`Q appeared in place of M (as above).
|
| 765 |
+
- Otherwise, Q undergoes unqualified lookup.
|
| 766 |
+
- Each lookup for Q considers only types (if Q is not followed by a `<`)
|
| 767 |
+
and templates whose specializations are types. If it finds nothing or
|
| 768 |
+
is ambiguous, it is discarded.
|
| 769 |
+
- The *type-name* that is or contains Q shall refer to its (original)
|
| 770 |
+
lookup context (ignoring cv-qualification) under the interpretation
|
| 771 |
+
established by at least one (successful) lookup performed.
|
| 772 |
+
|
| 773 |
+
[*Example 4*:
|
| 774 |
+
|
| 775 |
``` cpp
|
| 776 |
struct C {
|
| 777 |
typedef int I;
|
| 778 |
};
|
| 779 |
typedef int I1, I2;
|
| 780 |
extern int* p;
|
| 781 |
extern int* q;
|
| 782 |
+
void f() {
|
| 783 |
p->C::I::~I(); // I is looked up in the scope of C
|
| 784 |
+
q->I1::~I2(); // I2 is found by unqualified lookup
|
| 785 |
+
}
|
| 786 |
struct A {
|
| 787 |
~A();
|
| 788 |
};
|
| 789 |
typedef A AB;
|
| 790 |
int main() {
|
|
|
|
| 793 |
}
|
| 794 |
```
|
| 795 |
|
| 796 |
— *end example*]
|
| 797 |
|
|
|
|
|
|
|
|
|
|
| 798 |
#### Class members <a id="class.qual">[[class.qual]]</a>
|
| 799 |
|
| 800 |
+
In a lookup for a qualified name N whose lookup context is a class C in
|
| 801 |
+
which function names are not ignored,[^4]
|
|
|
|
|
|
|
|
|
|
| 802 |
|
| 803 |
+
- if the search finds the injected-class-name of `C` [[class.pre]], or
|
| 804 |
+
- if N is dependent and is the terminal name of a *using-declarator*
|
| 805 |
+
[[namespace.udecl]] that names a constructor,
|
| 806 |
|
| 807 |
+
N is instead considered to name the constructor of class `C`. Such a
|
| 808 |
+
constructor name shall be used only in the *declarator-id* of a (friend)
|
| 809 |
+
declaration of a constructor or in a *using-declaration*.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 810 |
|
| 811 |
[*Example 1*:
|
| 812 |
|
| 813 |
``` cpp
|
| 814 |
struct A { A(); };
|
|
|
|
| 822 |
struct A::A a2; // object of type A
|
| 823 |
```
|
| 824 |
|
| 825 |
— *end example*]
|
| 826 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 827 |
#### Namespace members <a id="namespace.qual">[[namespace.qual]]</a>
|
| 828 |
|
| 829 |
+
Qualified name lookup in a namespace N additionally searches every
|
| 830 |
+
element of the inline namespace set of N [[namespace.def]]. If nothing
|
| 831 |
+
is found, the results of the lookup are the results of qualified name
|
| 832 |
+
lookup in each namespace nominated by a *using-directive* that precedes
|
| 833 |
+
the point of the lookup and inhabits N or an element of N’s inline
|
| 834 |
+
namespace set.
|
| 835 |
|
| 836 |
+
[*Note 1*: If a *using-directive* refers to a namespace that has
|
| 837 |
+
already been considered, it does not affect the result. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
|
| 839 |
[*Example 1*:
|
| 840 |
|
| 841 |
``` cpp
|
| 842 |
int x;
|
|
|
|
| 890 |
}
|
| 891 |
```
|
| 892 |
|
| 893 |
— *end example*]
|
| 894 |
|
| 895 |
+
[*Note 2*:
|
| 896 |
|
| 897 |
The same declaration found more than once is not an ambiguity (because
|
| 898 |
it is still a unique declaration).
|
| 899 |
|
| 900 |
[*Example 2*:
|
|
|
|
| 917 |
using namespace C;
|
| 918 |
}
|
| 919 |
|
| 920 |
void f()
|
| 921 |
{
|
| 922 |
+
BC::a++; // OK, S is { `A::a`, `A::a` }
|
| 923 |
}
|
| 924 |
|
| 925 |
namespace D {
|
| 926 |
using A::a;
|
| 927 |
}
|
|
|
|
| 931 |
using namespace D;
|
| 932 |
}
|
| 933 |
|
| 934 |
void g()
|
| 935 |
{
|
| 936 |
+
BD::a++; // OK, S is { `A::a`, `A::a` }
|
| 937 |
}
|
| 938 |
```
|
| 939 |
|
| 940 |
— *end example*]
|
| 941 |
|
|
|
|
| 960 |
using namespace A;
|
| 961 |
}
|
| 962 |
|
| 963 |
void f()
|
| 964 |
{
|
| 965 |
+
A::a++; // OK, a declared directly in A, S is { `A::a` }
|
| 966 |
+
B::a++; // OK, both A and B searched (once), S is { `A::a` }
|
| 967 |
+
A::b++; // OK, both A and B searched (once), S is { `B::b` }
|
| 968 |
+
B::b++; // OK, b declared directly in B, S is { `B::b` }
|
| 969 |
}
|
| 970 |
```
|
| 971 |
|
| 972 |
— *end example*]
|
| 973 |
|
| 974 |
+
[*Note 3*: Class and enumeration declarations are not discarded because
|
| 975 |
+
of other declarations found in other searches. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 976 |
|
| 977 |
[*Example 4*:
|
| 978 |
|
| 979 |
``` cpp
|
| 980 |
namespace A {
|
|
|
|
| 995 |
}
|
| 996 |
```
|
| 997 |
|
| 998 |
— *end example*]
|
| 999 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1000 |
### Elaborated type specifiers <a id="basic.lookup.elab">[[basic.lookup.elab]]</a>
|
| 1001 |
|
| 1002 |
+
If the *class-key* or `enum` keyword in an *elaborated-type-specifier*
|
| 1003 |
+
is followed by an *identifier* that is not followed by `::`, lookup for
|
| 1004 |
+
the *identifier* is type-only [[basic.lookup.general]].
|
| 1005 |
+
|
| 1006 |
+
[*Note 1*: In general, the recognition of an
|
| 1007 |
+
*elaborated-type-specifier* depends on the following tokens. If the
|
| 1008 |
+
*identifier* is followed by `::`, see
|
| 1009 |
+
[[basic.lookup.qual]]. — *end note*]
|
| 1010 |
+
|
| 1011 |
+
If the terminal name of the *elaborated-type-specifier* is a qualified
|
| 1012 |
+
name, lookup for it is type-only. If the name lookup does not find a
|
| 1013 |
+
previously declared *type-name*, the *elaborated-type-specifier* is
|
| 1014 |
+
ill-formed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1015 |
|
| 1016 |
[*Example 1*:
|
| 1017 |
|
| 1018 |
``` cpp
|
| 1019 |
struct Node {
|
| 1020 |
+
struct Node* Next; // OK, refers to injected-class-name Node
|
| 1021 |
+
struct Data* Data; // OK, declares type Data at global scope and member Data
|
| 1022 |
};
|
| 1023 |
|
| 1024 |
struct Data {
|
| 1025 |
+
struct Node* Node; // OK, refers to Node at global scope
|
| 1026 |
friend struct ::Glob; // error: Glob is not declared, cannot introduce a qualified type[dcl.type.elab]
|
| 1027 |
+
friend struct Glob; // OK, refers to (as yet) undeclared Glob at global scope.
|
| 1028 |
...
|
| 1029 |
};
|
| 1030 |
|
| 1031 |
struct Base {
|
| 1032 |
+
struct Data; // OK, declares nested Data
|
| 1033 |
+
struct ::Data* thatData; // OK, refers to ::Data
|
| 1034 |
+
struct Base::Data* thisData; // OK, refers to nested Data
|
| 1035 |
+
friend class ::Data; // OK, global Data is a friend
|
| 1036 |
+
friend class Data; // OK, nested Data is a friend
|
| 1037 |
struct Data { ... }; // Defines nested Data
|
| 1038 |
};
|
| 1039 |
|
| 1040 |
+
struct Data; // OK, redeclares Data at global scope
|
| 1041 |
struct ::Data; // error: cannot introduce a qualified type[dcl.type.elab]
|
| 1042 |
struct Base::Data; // error: cannot introduce a qualified type[dcl.type.elab]
|
| 1043 |
struct Base::Datum; // error: Datum undefined
|
| 1044 |
+
struct Base::Data* pBase; // OK, refers to nested Data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1045 |
```
|
| 1046 |
|
| 1047 |
— *end example*]
|
| 1048 |
|
| 1049 |
### Using-directives and namespace aliases <a id="basic.lookup.udir">[[basic.lookup.udir]]</a>
|