- tmp/tmpzzbx9avf/{from.md → to.md} +233 -133
tmp/tmpzzbx9avf/{from.md → to.md}
RENAMED
|
@@ -1,34 +1,33 @@
|
|
| 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
|
| 5 |
[[basic.namespace]]), and *class-name*s ([[class.name]])) wherever the
|
| 6 |
grammar allows such names in the context discussed by a particular rule.
|
| 7 |
-
Name lookup associates the use of a name with a
|
| 8 |
-
[[basic.def]]) of that name.
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
[[
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
name’s declaration used further in expression processing (Clause
|
| 19 |
-
[[expr]]).
|
| 20 |
|
| 21 |
A name “looked up in the context of an expression” is looked up as an
|
| 22 |
unqualified name in the scope where the expression is found.
|
| 23 |
|
| 24 |
The injected-class-name of a class (Clause [[class]]) is also
|
| 25 |
considered to be a member of that class for the purposes of name hiding
|
| 26 |
and lookup.
|
| 27 |
|
| 28 |
-
[[basic.link]] discusses linkage issues. The notions of
|
| 29 |
-
declaration and name hiding are discussed in
|
|
|
|
| 30 |
|
| 31 |
### Unqualified name lookup <a id="basic.lookup.unqual">[[basic.lookup.unqual]]</a>
|
| 32 |
|
| 33 |
In all the cases listed in [[basic.lookup.unqual]], the scopes are
|
| 34 |
searched for a declaration in the order listed in each of the respective
|
|
@@ -41,12 +40,15 @@ become visible in a namespace enclosing the *using-directive*; see
|
|
| 41 |
described in [[basic.lookup.unqual]], the declarations from the
|
| 42 |
namespace nominated by the *using-directive* are considered members of
|
| 43 |
that enclosing namespace.
|
| 44 |
|
| 45 |
The lookup for an unqualified name used as the *postfix-expression* of a
|
| 46 |
-
function call is described in [[basic.lookup.argdep]].
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
*postfix-expression* for a function call, the usual name lookup rules
|
| 49 |
apply. The rules in [[basic.lookup.argdep]] have no effect on the
|
| 50 |
syntactic interpretation of an expression. For example,
|
| 51 |
|
| 52 |
``` cpp
|
|
@@ -54,37 +56,39 @@ typedef int f;
|
|
| 54 |
namespace N {
|
| 55 |
struct A {
|
| 56 |
friend void f(A &);
|
| 57 |
operator int();
|
| 58 |
void g(A a) {
|
| 59 |
-
int i = f(a);
|
| 60 |
-
// function: equivalent to int(a)
|
| 61 |
}
|
| 62 |
};
|
| 63 |
}
|
| 64 |
```
|
| 65 |
|
| 66 |
Because the expression is not a function call, the argument-dependent
|
| 67 |
name lookup ([[basic.lookup.argdep]]) does not apply and the friend
|
| 68 |
function `f` is not found.
|
| 69 |
|
|
|
|
|
|
|
| 70 |
A name used in global scope, outside of any function, class or
|
| 71 |
user-declared namespace, shall be declared before its use in global
|
| 72 |
scope.
|
| 73 |
|
| 74 |
A name used in a user-declared namespace outside of the definition of
|
| 75 |
any function or class shall be declared before its use in that namespace
|
| 76 |
or before its use in a namespace enclosing its namespace.
|
| 77 |
|
| 78 |
-
|
| 79 |
-
*declarator-id*[^4]
|
| 80 |
-
the
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
use in namespace `N` or, if `N` is a nested namespace, shall be declared
|
| 84 |
before its use in one of `N`’s enclosing namespaces.
|
| 85 |
|
|
|
|
|
|
|
| 86 |
``` cpp
|
| 87 |
namespace A {
|
| 88 |
namespace N {
|
| 89 |
void f();
|
| 90 |
}
|
|
@@ -97,30 +101,34 @@ void A::N::f() {
|
|
| 97 |
// 3) scope of namespace A
|
| 98 |
// 4) global scope, before the definition of A::N::f
|
| 99 |
}
|
| 100 |
```
|
| 101 |
|
|
|
|
|
|
|
| 102 |
A name used in the definition of a class `X` outside of a member
|
| 103 |
-
function body, default argument, *
|
| 104 |
*brace-or-equal-initializer* of a non-static data member, or nested
|
| 105 |
class definition[^5] shall be declared in one of the following ways:
|
| 106 |
|
| 107 |
- before its use in class `X` or be a member of a base class of `X` (
|
| 108 |
[[class.member.lookup]]), or
|
| 109 |
- if `X` is a nested class of class `Y` ([[class.nest]]), before the
|
| 110 |
definition of `X` in `Y`, or shall be a member of a base class of `Y`
|
| 111 |
-
(this lookup applies in turn to `Y`
|
| 112 |
-
|
| 113 |
- if `X` is a local class ([[class.local]]) or is a nested class of a
|
| 114 |
local class, before the definition of class `X` in a block enclosing
|
| 115 |
the definition of class `X`, or
|
| 116 |
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 117 |
that is a member of `N`, or is a local class or a nested class within
|
| 118 |
a local class of a function that is a member of `N`, before the
|
| 119 |
definition of class `X` in namespace `N` or in one of `N`’s enclosing
|
| 120 |
namespaces.
|
| 121 |
|
|
|
|
|
|
|
| 122 |
``` cpp
|
| 123 |
namespace M {
|
| 124 |
class B { };
|
| 125 |
}
|
| 126 |
```
|
|
@@ -140,21 +148,25 @@ namespace N {
|
|
| 140 |
// 3) scope of N::Y's base class M::B
|
| 141 |
// 4) scope of namespace N, before the definition of N::Y
|
| 142 |
// 5) global scope, before the definition of N
|
| 143 |
```
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
[[class.local]] further describes the restrictions on the use of names
|
| 152 |
-
in local class definitions.
|
| 153 |
|
| 154 |
For the members of a class `X`, a name used in a member function body,
|
| 155 |
-
in a default argument, in
|
| 156 |
*brace-or-equal-initializer* of a non-static data member (
|
| 157 |
[[class.mem]]), or in the definition of a class member outside of the
|
| 158 |
definition of `X`, following the member’s *declarator-id*[^7], shall be
|
| 159 |
declared in one of the following ways:
|
| 160 |
|
|
@@ -172,10 +184,12 @@ declared in one of the following ways:
|
|
| 172 |
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 173 |
that is a member of `N`, or is a local class or a nested class within
|
| 174 |
a local class of a function that is a member of `N`, before the use of
|
| 175 |
the name, in namespace `N` or in one of `N`’s enclosing namespaces.
|
| 176 |
|
|
|
|
|
|
|
| 177 |
``` cpp
|
| 178 |
class B { };
|
| 179 |
namespace M {
|
| 180 |
namespace N {
|
| 181 |
class X : public B {
|
|
@@ -194,15 +208,18 @@ void M::N::X::f() {
|
|
| 194 |
// 4) scope of namespace M::N
|
| 195 |
// 5) scope of namespace M
|
| 196 |
// 6) global scope, before the definition of M::N::X::f
|
| 197 |
```
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
the use of names in
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
Name lookup for a name used in the definition of a `friend` function (
|
| 206 |
[[class.friend]]) defined inline in the class granting friendship shall
|
| 207 |
proceed as described for lookup in member function definitions. If the
|
| 208 |
`friend` function is not defined in the class granting friendship, name
|
|
@@ -215,10 +232,12 @@ function declarator and not part of a *template-argument* in the
|
|
| 215 |
class ([[class.member.lookup]]). If it is not found, or if the name is
|
| 216 |
part of a *template-argument* in the *declarator-id*, the look up is as
|
| 217 |
described for unqualified names in the definition of the class granting
|
| 218 |
friendship.
|
| 219 |
|
|
|
|
|
|
|
| 220 |
``` cpp
|
| 221 |
struct A {
|
| 222 |
typedef int AT;
|
| 223 |
void f1(AT);
|
| 224 |
void f2(float);
|
|
@@ -231,36 +250,44 @@ struct B {
|
|
| 231 |
friend void A::f2(BT); // parameter type is B::BT
|
| 232 |
friend void A::f3<AT>(); // template argument is B::AT
|
| 233 |
};
|
| 234 |
```
|
| 235 |
|
|
|
|
|
|
|
| 236 |
During the lookup for a name used as a default argument (
|
| 237 |
[[dcl.fct.default]]) in a function *parameter-declaration-clause* or
|
| 238 |
used in the *expression* of a *mem-initializer* for a constructor (
|
| 239 |
[[class.base.init]]), the function parameter names are visible and hide
|
| 240 |
the names of entities declared in the block, class or namespace scopes
|
| 241 |
-
containing the function declaration.
|
| 242 |
-
|
| 243 |
-
[[
|
| 244 |
-
names in
|
|
|
|
|
|
|
| 245 |
|
| 246 |
During the lookup of a name used in the *constant-expression* of an
|
| 247 |
*enumerator-definition*, previously declared *enumerator*s of the
|
| 248 |
enumeration are visible and hide the names of entities declared in the
|
| 249 |
block, class, or namespace scopes containing the *enum-specifier*.
|
| 250 |
|
| 251 |
A name used in the definition of a `static` data member of class `X` (
|
| 252 |
[[class.static.data]]) (after the *qualified-id* of the static member)
|
| 253 |
is looked up as if the name was used in a member function of `X`.
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
| 256 |
|
| 257 |
If a variable member of a namespace is defined outside of the scope of
|
| 258 |
its namespace then any name that appears in the definition of the member
|
| 259 |
(after the *declarator-id*) is looked up as if the definition of the
|
| 260 |
member occurred in its namespace.
|
| 261 |
|
|
|
|
|
|
|
| 262 |
``` cpp
|
| 263 |
namespace N {
|
| 264 |
int i = 4;
|
| 265 |
extern int j;
|
| 266 |
}
|
|
@@ -268,21 +295,24 @@ namespace N {
|
|
| 268 |
int i = 2;
|
| 269 |
|
| 270 |
int N::j = i; // N::j == 4
|
| 271 |
```
|
| 272 |
|
|
|
|
|
|
|
| 273 |
A name used in the handler for a *function-try-block* (Clause
|
| 274 |
[[except]]) is looked up as if the name was used in the outermost block
|
| 275 |
of the function definition. In particular, the function parameter names
|
| 276 |
shall not be redeclared in the *exception-declaration* nor in the
|
| 277 |
outermost block of a handler for the *function-try-block*. Names
|
| 278 |
declared in the outermost block of the function definition are not found
|
| 279 |
when looked up in the scope of a handler for the *function-try-block*.
|
| 280 |
-
But function parameter names are found.
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
| 284 |
|
| 285 |
### Argument-dependent name lookup <a id="basic.lookup.argdep">[[basic.lookup.argdep]]</a>
|
| 286 |
|
| 287 |
When the *postfix-expression* in a function call ([[expr.call]]) is an
|
| 288 |
*unqualified-id*, other namespaces not considered during the usual
|
|
@@ -291,27 +321,30 @@ those namespaces, namespace-scope friend function or function template
|
|
| 291 |
declarations ([[class.friend]]) not otherwise visible may be found.
|
| 292 |
These modifications to the search depend on the types of the arguments
|
| 293 |
(and for template template arguments, the namespace of the template
|
| 294 |
argument).
|
| 295 |
|
|
|
|
|
|
|
| 296 |
``` cpp
|
| 297 |
namespace N {
|
| 298 |
struct S { };
|
| 299 |
void f(S);
|
| 300 |
}
|
| 301 |
|
| 302 |
void g() {
|
| 303 |
N::S s;
|
| 304 |
f(s); // OK: calls N::f
|
| 305 |
-
(f)(s);
|
| 306 |
-
// prevent argument-dependent lookup
|
| 307 |
}
|
| 308 |
```
|
| 309 |
|
|
|
|
|
|
|
| 310 |
For each argument type `T` in the function call, there is a set of zero
|
| 311 |
-
or more associated namespaces and a set of zero or more associated
|
| 312 |
-
classes to be considered. The sets of namespaces and classes
|
| 313 |
determined entirely by the types of the function arguments (and the
|
| 314 |
namespace of any template template argument). Typedef names and
|
| 315 |
*using-declaration*s used to specify the types do not contribute to this
|
| 316 |
set. The sets of namespaces and classes are determined in the following
|
| 317 |
way:
|
|
@@ -326,12 +359,12 @@ way:
|
|
| 326 |
and classes also include: the namespaces and classes associated with
|
| 327 |
the types of the template arguments provided for template type
|
| 328 |
parameters (excluding template template parameters); the namespaces of
|
| 329 |
which any template template arguments are members; and the classes of
|
| 330 |
which any member templates used as template template arguments are
|
| 331 |
-
members. Non-type template arguments do not contribute to
|
| 332 |
-
associated namespaces.
|
| 333 |
- If `T` is an enumeration type, its associated namespace is the
|
| 334 |
innermost enclosing namespace of its declaration. If it is a class
|
| 335 |
member, its associated class is the member’s class; else it has no
|
| 336 |
associated class.
|
| 337 |
- If `T` is a pointer to `U` or an array of `U`, its associated
|
|
@@ -364,18 +397,22 @@ Let *X* be the lookup set produced by unqualified lookup (
|
|
| 364 |
argument dependent lookup (defined as follows). If *X* contains
|
| 365 |
|
| 366 |
- a declaration of a class member, or
|
| 367 |
- a block-scope function declaration that is not a *using-declaration*,
|
| 368 |
or
|
| 369 |
-
- a declaration that is neither a function
|
| 370 |
|
| 371 |
then *Y* is empty. Otherwise *Y* is the set of declarations found in the
|
| 372 |
namespaces associated with the argument types as described below. The
|
| 373 |
set of declarations found by the lookup of the name is the union of *X*
|
| 374 |
-
and *Y*.
|
| 375 |
-
|
| 376 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
|
| 378 |
``` cpp
|
| 379 |
namespace NS {
|
| 380 |
class T { };
|
| 381 |
void f(T);
|
|
@@ -388,10 +425,12 @@ int main() {
|
|
| 388 |
extern void g(NS::T, float);
|
| 389 |
g(parm, 1); // OK: calls g(NS::T, float)
|
| 390 |
}
|
| 391 |
```
|
| 392 |
|
|
|
|
|
|
|
| 393 |
When considering an associated namespace, the lookup is the same as the
|
| 394 |
lookup performed when the associated namespace is used as a qualifier (
|
| 395 |
[[namespace.qual]]) except that:
|
| 396 |
|
| 397 |
- Any *using-directive*s in the associated namespace are ignored.
|
|
@@ -412,10 +451,12 @@ enumeration. If a `::` scope resolution operator in a
|
|
| 412 |
lookup of the name preceding that `::` considers only namespaces, types,
|
| 413 |
and templates whose specializations are types. If the name found does
|
| 414 |
not designate a namespace or a class, enumeration, or dependent type,
|
| 415 |
the program is ill-formed.
|
| 416 |
|
|
|
|
|
|
|
| 417 |
``` cpp
|
| 418 |
class A {
|
| 419 |
public:
|
| 420 |
static int n;
|
| 421 |
};
|
|
@@ -424,31 +465,37 @@ int main() {
|
|
| 424 |
A::n = 42; // OK
|
| 425 |
A b; // ill-formed: A does not name a type
|
| 426 |
}
|
| 427 |
```
|
| 428 |
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
|
|
|
|
|
|
| 432 |
|
| 433 |
In a declaration in which the *declarator-id* is a *qualified-id*, names
|
| 434 |
used before the *qualified-id* being declared are looked up in the
|
| 435 |
defining namespace scope; names following the *qualified-id* are looked
|
| 436 |
up in the scope of the member’s class or namespace.
|
| 437 |
|
|
|
|
|
|
|
| 438 |
``` cpp
|
| 439 |
class X { };
|
| 440 |
class C {
|
| 441 |
class X { };
|
| 442 |
static const int number = 50;
|
| 443 |
static X arr[number];
|
| 444 |
};
|
| 445 |
X C::arr[number]; // ill-formed:
|
| 446 |
-
// equivalent to
|
| 447 |
-
// not to
|
| 448 |
```
|
| 449 |
|
|
|
|
|
|
|
| 450 |
A name prefixed by the unary scope operator `::` ([[expr.prim]]) is
|
| 451 |
looked up in global scope, in the translation unit where it is used. The
|
| 452 |
name shall be declared in global namespace scope or shall be a name
|
| 453 |
whose declaration is visible in global scope because of a
|
| 454 |
*using-directive* ([[namespace.qual]]). The use of `::` allows a global
|
|
@@ -467,20 +514,21 @@ scope designated by the *nested-name-specifier*. Similarly, in a
|
|
| 467 |
nested-name-specifierₒₚₜ class-name '::' '~' class-name
|
| 468 |
```
|
| 469 |
|
| 470 |
the second *class-name* is looked up in the same scope as the first.
|
| 471 |
|
|
|
|
|
|
|
| 472 |
``` cpp
|
| 473 |
struct C {
|
| 474 |
typedef int I;
|
| 475 |
};
|
| 476 |
typedef int I1, I2;
|
| 477 |
extern int* p;
|
| 478 |
extern int* q;
|
| 479 |
p->C::I::~I(); // I is looked up in the scope of C
|
| 480 |
-
q->I1::~I2(); // I2 is looked up in the scope of
|
| 481 |
-
// the postfix-expression
|
| 482 |
|
| 483 |
struct A {
|
| 484 |
~A();
|
| 485 |
};
|
| 486 |
typedef A AB;
|
|
@@ -488,25 +536,30 @@ int main() {
|
|
| 488 |
AB* p;
|
| 489 |
p->AB::~AB(); // explicitly calls the destructor for A
|
| 490 |
}
|
| 491 |
```
|
| 492 |
|
| 493 |
-
|
| 494 |
-
|
|
|
|
|
|
|
| 495 |
|
| 496 |
#### Class members <a id="class.qual">[[class.qual]]</a>
|
| 497 |
|
| 498 |
If the *nested-name-specifier* of a *qualified-id* nominates a class,
|
| 499 |
the name specified after the *nested-name-specifier* is looked up in the
|
| 500 |
scope of the class ([[class.member.lookup]]), except for the cases
|
| 501 |
listed below. The name shall represent one or more members of that class
|
| 502 |
-
or of one of its base classes (Clause [[class.derived]]).
|
| 503 |
-
member can be referred to using a *qualified-id* at any point in its
|
| 504 |
-
potential scope ([[basic.scope.class]]). The exceptions to the name
|
| 505 |
-
lookup rule above are the following:
|
| 506 |
|
| 507 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
- a *conversion-type-id* of a *conversion-function-id* is looked up in
|
| 509 |
the same manner as a *conversion-type-id* in a class member access
|
| 510 |
(see [[basic.lookup.classref]]);
|
| 511 |
- the names in a *template-argument* of a *template-id* are looked up in
|
| 512 |
the context in which the entire *postfix-expression* occurs.
|
|
@@ -517,22 +570,26 @@ lookup rule above are the following:
|
|
| 517 |
In a lookup in which function names are not ignored[^9] and the
|
| 518 |
*nested-name-specifier* nominates a class `C`:
|
| 519 |
|
| 520 |
- if the name specified after the *nested-name-specifier*, when looked
|
| 521 |
up in `C`, is the injected-class-name of `C` (Clause [[class]]), or
|
| 522 |
-
- in a *using-
|
| 523 |
-
*member-declaration*, if the name
|
| 524 |
-
*nested-name-specifier* is the same as the
|
| 525 |
-
*simple-template-id*’s *template-name* in the last
|
| 526 |
-
*nested-name-specifier*,
|
| 527 |
-
|
| 528 |
-
the name is instead considered to name the constructor of class `C`.
|
| 529 |
-
|
| 530 |
-
*
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
|
| 535 |
``` cpp
|
| 536 |
struct A { A(); };
|
| 537 |
struct B: public A { B(); };
|
| 538 |
|
|
@@ -542,39 +599,42 @@ B::B() { }
|
|
| 542 |
B::A ba; // object of type A
|
| 543 |
A::A a; // error, A::A is not a type name
|
| 544 |
struct A::A a2; // object of type A
|
| 545 |
```
|
| 546 |
|
|
|
|
|
|
|
| 547 |
A class member name hidden by a name in a nested declarative region or
|
| 548 |
by the name of a derived class member can still be found if qualified by
|
| 549 |
the name of its class followed by the `::` operator.
|
| 550 |
|
| 551 |
#### Namespace members <a id="namespace.qual">[[namespace.qual]]</a>
|
| 552 |
|
| 553 |
-
If the *nested-name-specifier* of a *qualified-id* nominates a
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
occurs.
|
| 560 |
|
| 561 |
For a namespace `X` and name `m`, the namespace-qualified lookup set
|
| 562 |
S(X, m) is defined as follows: Let S'(X, m) be the set of all
|
| 563 |
declarations of `m` in `X` and the inline namespace set of `X` (
|
| 564 |
[[namespace.def]]). If S'(X, m) is not empty, S(X, m) is S'(X, m);
|
| 565 |
otherwise, S(X, m) is the union of S(Nᵢ, m) for all namespaces Nᵢ
|
| 566 |
-
nominated by *using-
|
| 567 |
|
| 568 |
Given `X::m` (where `X` is a user-declared namespace), or given `::m`
|
| 569 |
(where X is the global namespace), if S(X, m) is the empty set, the
|
| 570 |
program is ill-formed. Otherwise, if S(X, m) has exactly one member, or
|
| 571 |
if the context of the reference is a *using-declaration* (
|
| 572 |
[[namespace.udecl]]), S(X, m) is the required set of declarations of
|
| 573 |
`m`. Otherwise if the use of `m` is not one that allows a unique
|
| 574 |
declaration to be chosen from S(X, m), the program is ill-formed.
|
| 575 |
|
|
|
|
|
|
|
| 576 |
``` cpp
|
| 577 |
int x;
|
| 578 |
namespace Y {
|
| 579 |
void f(float);
|
| 580 |
void h(int);
|
|
@@ -603,38 +663,38 @@ namespace AB {
|
|
| 603 |
void g();
|
| 604 |
}
|
| 605 |
|
| 606 |
void h()
|
| 607 |
{
|
| 608 |
-
AB::g(); // g is declared directly in AB,
|
| 609 |
-
|
| 610 |
-
AB::f(1); // f is not declared directly in AB so the rules are
|
| 611 |
-
//
|
| 612 |
-
//
|
| 613 |
-
|
| 614 |
-
// S is { A::f(int), B::f(char) } and overload
|
| 615 |
-
// resolution chooses A::f(int)
|
| 616 |
AB::f('c'); // as above but resolution chooses B::f(char)
|
| 617 |
|
| 618 |
-
AB::x++; // x is not declared directly in AB, and
|
| 619 |
-
//
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
// and
|
| 626 |
-
|
| 627 |
-
// not declared directly in A or B so the rules are
|
| 628 |
-
// applied recursively to Y and Z,
|
| 629 |
-
// S is { Y::h(int), Z::h(double) } and overload
|
| 630 |
-
// resolution chooses Z::h(double)
|
| 631 |
}
|
| 632 |
```
|
| 633 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
The same declaration found more than once is not an ambiguity (because
|
| 635 |
-
it is still a unique declaration).
|
|
|
|
|
|
|
| 636 |
|
| 637 |
``` cpp
|
| 638 |
namespace A {
|
| 639 |
int a;
|
| 640 |
}
|
|
@@ -652,11 +712,11 @@ namespace BC {
|
|
| 652 |
using namespace C;
|
| 653 |
}
|
| 654 |
|
| 655 |
void f()
|
| 656 |
{
|
| 657 |
-
BC::a++; // OK: S is { A::a, A::a }
|
| 658 |
}
|
| 659 |
|
| 660 |
namespace D {
|
| 661 |
using A::a;
|
| 662 |
}
|
|
@@ -666,14 +726,20 @@ namespace BD {
|
|
| 666 |
using namespace D;
|
| 667 |
}
|
| 668 |
|
| 669 |
void g()
|
| 670 |
{
|
| 671 |
-
BD::a++; // OK: S is {
|
| 672 |
}
|
| 673 |
```
|
| 674 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 675 |
Because each referenced namespace is searched at most once, the
|
| 676 |
following is well-defined:
|
| 677 |
|
| 678 |
``` cpp
|
| 679 |
namespace B {
|
|
@@ -689,25 +755,29 @@ namespace B {
|
|
| 689 |
using namespace A;
|
| 690 |
}
|
| 691 |
|
| 692 |
void f()
|
| 693 |
{
|
| 694 |
-
A::a++; // OK: a declared directly in A, S is {A::a}
|
| 695 |
-
B::a++; // OK: both A and B searched (once), S is {A::a}
|
| 696 |
-
A::b++; // OK: both A and B searched (once), S is {B::b}
|
| 697 |
-
B::b++; // OK: b declared directly in B, S is {B::b}
|
| 698 |
}
|
| 699 |
```
|
| 700 |
|
|
|
|
|
|
|
| 701 |
During the lookup of a qualified namespace member name, if the lookup
|
| 702 |
finds more than one declaration of the member, and if one declaration
|
| 703 |
introduces a class name or enumeration name and the other declarations
|
| 704 |
either introduce the same variable, the same enumerator or a set of
|
| 705 |
functions, the non-type name hides the class or enumeration name if and
|
| 706 |
only if the declarations are from the same namespace; otherwise (the
|
| 707 |
declarations are from different namespaces), the program is ill-formed.
|
| 708 |
|
|
|
|
|
|
|
| 709 |
``` cpp
|
| 710 |
namespace A {
|
| 711 |
struct x { };
|
| 712 |
int x;
|
| 713 |
int y;
|
|
@@ -723,10 +793,12 @@ namespace C {
|
|
| 723 |
int i = C::x; // OK, A::x (of type int)
|
| 724 |
int j = C::y; // ambiguous, A::y or B::y
|
| 725 |
}
|
| 726 |
```
|
| 727 |
|
|
|
|
|
|
|
| 728 |
In a declaration for a namespace member in which the *declarator-id* is
|
| 729 |
a *qualified-id*, given that the *qualified-id* for the namespace member
|
| 730 |
has the form
|
| 731 |
|
| 732 |
``` bnf
|
|
@@ -735,24 +807,30 @@ nested-name-specifier unqualified-id
|
|
| 735 |
|
| 736 |
the *unqualified-id* shall name a member of the namespace designated by
|
| 737 |
the *nested-name-specifier* or of an element of the inline namespace
|
| 738 |
set ([[namespace.def]]) of that namespace.
|
| 739 |
|
|
|
|
|
|
|
| 740 |
``` cpp
|
| 741 |
namespace A {
|
| 742 |
namespace B {
|
| 743 |
void f1(int);
|
| 744 |
}
|
| 745 |
using namespace B;
|
| 746 |
}
|
| 747 |
void A::f1(int){ } // ill-formed, f1 is not a member of A
|
| 748 |
```
|
| 749 |
|
|
|
|
|
|
|
| 750 |
However, in such namespace member declarations, the
|
| 751 |
*nested-name-specifier* may rely on *using-directive*s to implicitly
|
| 752 |
provide the initial part of the *nested-name-specifier*.
|
| 753 |
|
|
|
|
|
|
|
| 754 |
``` cpp
|
| 755 |
namespace A {
|
| 756 |
namespace B {
|
| 757 |
void f1(int);
|
| 758 |
}
|
|
@@ -767,10 +845,12 @@ namespace C {
|
|
| 767 |
using namespace A;
|
| 768 |
using namespace C::D;
|
| 769 |
void B::f1(int){ } // OK, defines A::B::f1(int)
|
| 770 |
```
|
| 771 |
|
|
|
|
|
|
|
| 772 |
### Elaborated type specifiers <a id="basic.lookup.elab">[[basic.lookup.elab]]</a>
|
| 773 |
|
| 774 |
An *elaborated-type-specifier* ([[dcl.type.elab]]) may be used to refer
|
| 775 |
to a previously declared *class-name* or *enum-name* even though the
|
| 776 |
name has been hidden by a non-type declaration (
|
|
@@ -804,42 +884,44 @@ If the *elaborated-type-specifier* has a *nested-name-specifier*,
|
|
| 804 |
qualified name lookup is performed, as described in
|
| 805 |
[[basic.lookup.qual]], but ignoring any non-type names that have been
|
| 806 |
declared. If the name lookup does not find a previously declared
|
| 807 |
*type-name*, the *elaborated-type-specifier* is ill-formed.
|
| 808 |
|
|
|
|
|
|
|
| 809 |
``` cpp
|
| 810 |
struct Node {
|
| 811 |
struct Node* Next; // OK: Refers to Node at global scope
|
| 812 |
struct Data* Data; // OK: Declares type Data
|
| 813 |
// at global scope and member Data
|
| 814 |
};
|
| 815 |
|
| 816 |
struct Data {
|
| 817 |
struct Node* Node; // OK: Refers to Node at global scope
|
| 818 |
-
friend struct ::Glob; // error: Glob is not declared
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
// at global scope.
|
| 822 |
-
/* ... */
|
| 823 |
};
|
| 824 |
|
| 825 |
struct Base {
|
| 826 |
struct Data; // OK: Declares nested Data
|
| 827 |
struct ::Data* thatData; // OK: Refers to ::Data
|
| 828 |
struct Base::Data* thisData; // OK: Refers to nested Data
|
| 829 |
friend class ::Data; // OK: global Data is a friend
|
| 830 |
friend class Data; // OK: nested Data is a friend
|
| 831 |
-
struct Data {
|
| 832 |
};
|
| 833 |
|
| 834 |
struct Data; // OK: Redeclares Data at global scope
|
| 835 |
struct ::Data; // error: cannot introduce a qualified type~([dcl.type.elab])
|
| 836 |
struct Base::Data; // error: cannot introduce a qualified type~([dcl.type.elab])
|
| 837 |
struct Base::Datum; // error: Datum undefined
|
| 838 |
struct Base::Data* pBase; // OK: refers to nested Data
|
| 839 |
```
|
| 840 |
|
|
|
|
|
|
|
| 841 |
### Class member access <a id="basic.lookup.classref">[[basic.lookup.classref]]</a>
|
| 842 |
|
| 843 |
In a class member access expression ([[expr.ref]]), if the `.` or `->`
|
| 844 |
token is immediately followed by an *identifier* followed by a `<`, the
|
| 845 |
identifier must be looked up to determine whether the `<` is the
|
|
@@ -857,11 +939,13 @@ looked up in the context of the complete *postfix-expression*.
|
|
| 857 |
|
| 858 |
If the *unqualified-id* is `~`*type-name*, the *type-name* is looked up
|
| 859 |
in the context of the entire *postfix-expression*. If the type `T` of
|
| 860 |
the object expression is of a class type `C`, the *type-name* is also
|
| 861 |
looked up in the scope of class `C`. At least one of the lookups shall
|
| 862 |
-
find a name that refers to
|
|
|
|
|
|
|
| 863 |
|
| 864 |
``` cpp
|
| 865 |
struct A { };
|
| 866 |
|
| 867 |
struct B {
|
|
@@ -872,22 +956,34 @@ struct B {
|
|
| 872 |
void B::f(::A* a) {
|
| 873 |
a->~A(); // OK: lookup in *a finds the injected-class-name
|
| 874 |
}
|
| 875 |
```
|
| 876 |
|
|
|
|
|
|
|
| 877 |
If the *id-expression* in a class member access is a *qualified-id* of
|
| 878 |
the form
|
| 879 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 880 |
the *class-name-or-namespace-name* following the `.` or `->` operator is
|
| 881 |
first looked up in the class of the object expression and the name, if
|
| 882 |
found, is used. Otherwise it is looked up in the context of the entire
|
| 883 |
-
*postfix-expression*.
|
| 884 |
-
|
| 885 |
-
|
|
|
|
|
|
|
| 886 |
|
| 887 |
If the *qualified-id* has the form
|
| 888 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 889 |
the *class-name-or-namespace-name* is looked up in global scope as a
|
| 890 |
*class-name* or *namespace-name*.
|
| 891 |
|
| 892 |
If the *nested-name-specifier* contains a *simple-template-id* (
|
| 893 |
[[temp.names]]), the names in its *template-argument*s are looked up in
|
|
@@ -898,10 +994,12 @@ If the *id-expression* is a *conversion-function-id*, its
|
|
| 898 |
expression and the name, if found, is used. Otherwise it is looked up in
|
| 899 |
the context of the entire *postfix-expression*. In each of these
|
| 900 |
lookups, only names that denote types or templates whose specializations
|
| 901 |
are types are considered.
|
| 902 |
|
|
|
|
|
|
|
| 903 |
``` cpp
|
| 904 |
struct A { };
|
| 905 |
namespace N {
|
| 906 |
struct A {
|
| 907 |
void g() { }
|
|
@@ -913,10 +1011,12 @@ int main() {
|
|
| 913 |
N::A a;
|
| 914 |
a.operator A(); // calls N::A::operator N::A
|
| 915 |
}
|
| 916 |
```
|
| 917 |
|
|
|
|
|
|
|
| 918 |
### Using-directives and namespace aliases <a id="basic.lookup.udir">[[basic.lookup.udir]]</a>
|
| 919 |
|
| 920 |
In a *using-directive* or *namespace-alias-definition*, during the
|
| 921 |
lookup for a *namespace-name* or for a name in a *nested-name-specifier*
|
| 922 |
only namespace names are considered.
|
|
|
|
| 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 (
|
| 5 |
[[basic.namespace]]), and *class-name*s ([[class.name]])) wherever the
|
| 6 |
grammar allows such names in the context discussed by a particular rule.
|
| 7 |
+
Name lookup associates the use of a name with a set of declarations (
|
| 8 |
+
[[basic.def]]) of that name. The declarations found by name lookup shall
|
| 9 |
+
either all declare the same entity or shall all declare functions; in
|
| 10 |
+
the latter case, the declarations are said to form a set of overloaded
|
| 11 |
+
functions ([[over.load]]). Overload resolution ([[over.match]]) takes
|
| 12 |
+
place after name lookup has succeeded. The access rules (Clause
|
| 13 |
+
[[class.access]]) are considered only once name lookup and function
|
| 14 |
+
overload resolution (if applicable) have succeeded. Only after name
|
| 15 |
+
lookup, function overload resolution (if applicable) and access checking
|
| 16 |
+
have succeeded are the attributes introduced by the name’s declaration
|
| 17 |
+
used further in expression processing (Clause [[expr]]).
|
|
|
|
|
|
|
| 18 |
|
| 19 |
A name “looked up in the context of an expression” is looked up as an
|
| 20 |
unqualified name in the scope where the expression is found.
|
| 21 |
|
| 22 |
The injected-class-name of a class (Clause [[class]]) is also
|
| 23 |
considered to be a member of that class for the purposes of name hiding
|
| 24 |
and lookup.
|
| 25 |
|
| 26 |
+
[*Note 1*: [[basic.link]] discusses linkage issues. The notions of
|
| 27 |
+
scope, point of declaration and name hiding are discussed in
|
| 28 |
+
[[basic.scope]]. — *end note*]
|
| 29 |
|
| 30 |
### Unqualified name lookup <a id="basic.lookup.unqual">[[basic.lookup.unqual]]</a>
|
| 31 |
|
| 32 |
In all the cases listed in [[basic.lookup.unqual]], the scopes are
|
| 33 |
searched for a declaration in the order listed in each of the respective
|
|
|
|
| 40 |
described in [[basic.lookup.unqual]], the declarations from the
|
| 41 |
namespace nominated by the *using-directive* are considered members of
|
| 42 |
that enclosing namespace.
|
| 43 |
|
| 44 |
The lookup for an unqualified name used as the *postfix-expression* of a
|
| 45 |
+
function call is described in [[basic.lookup.argdep]].
|
| 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
|
| 51 |
apply. The rules in [[basic.lookup.argdep]] have no effect on the
|
| 52 |
syntactic interpretation of an expression. For example,
|
| 53 |
|
| 54 |
``` cpp
|
|
|
|
| 56 |
namespace N {
|
| 57 |
struct A {
|
| 58 |
friend void f(A &);
|
| 59 |
operator int();
|
| 60 |
void g(A a) {
|
| 61 |
+
int i = f(a); // f is the typedef, not the friend function: equivalent to int(a)
|
|
|
|
| 62 |
}
|
| 63 |
};
|
| 64 |
}
|
| 65 |
```
|
| 66 |
|
| 67 |
Because the expression is not a function call, the argument-dependent
|
| 68 |
name lookup ([[basic.lookup.argdep]]) does not apply and the friend
|
| 69 |
function `f` is not found.
|
| 70 |
|
| 71 |
+
— *end note*]
|
| 72 |
+
|
| 73 |
A name used in global scope, outside of any function, class or
|
| 74 |
user-declared namespace, shall be declared before its use in global
|
| 75 |
scope.
|
| 76 |
|
| 77 |
A name used in a user-declared namespace outside of the definition of
|
| 78 |
any function or class shall be declared before its use in that namespace
|
| 79 |
or before its use in a namespace enclosing its namespace.
|
| 80 |
|
| 81 |
+
In the definition of a function that is a member of namespace `N`, a
|
| 82 |
+
name used after the function’s *declarator-id*[^4] shall be declared
|
| 83 |
+
before its use in the block in which it is used or in one of its
|
| 84 |
+
enclosing blocks ([[stmt.block]]) or shall be declared before its use
|
| 85 |
+
in namespace `N` or, if `N` is a nested namespace, shall be declared
|
|
|
|
| 86 |
before its use in one of `N`’s enclosing namespaces.
|
| 87 |
|
| 88 |
+
[*Example 1*:
|
| 89 |
+
|
| 90 |
``` cpp
|
| 91 |
namespace A {
|
| 92 |
namespace N {
|
| 93 |
void f();
|
| 94 |
}
|
|
|
|
| 101 |
// 3) scope of namespace A
|
| 102 |
// 4) global scope, before the definition of A::N::f
|
| 103 |
}
|
| 104 |
```
|
| 105 |
|
| 106 |
+
— *end example*]
|
| 107 |
+
|
| 108 |
A name used in the definition of a class `X` outside of a member
|
| 109 |
+
function body, default argument, *noexcept-specifier*,
|
| 110 |
*brace-or-equal-initializer* of a non-static data member, or nested
|
| 111 |
class definition[^5] shall be declared in one of the following ways:
|
| 112 |
|
| 113 |
- before its use in class `X` or be a member of a base class of `X` (
|
| 114 |
[[class.member.lookup]]), or
|
| 115 |
- if `X` is a nested class of class `Y` ([[class.nest]]), before the
|
| 116 |
definition of `X` in `Y`, or shall be a member of a base class of `Y`
|
| 117 |
+
(this lookup applies in turn to `Y`’s enclosing classes, starting with
|
| 118 |
+
the innermost enclosing class),[^6] or
|
| 119 |
- if `X` is a local class ([[class.local]]) or is a nested class of a
|
| 120 |
local class, before the definition of class `X` in a block enclosing
|
| 121 |
the definition of class `X`, or
|
| 122 |
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 123 |
that is a member of `N`, or is a local class or a nested class within
|
| 124 |
a local class of a function that is a member of `N`, before the
|
| 125 |
definition of class `X` in namespace `N` or in one of `N`’s enclosing
|
| 126 |
namespaces.
|
| 127 |
|
| 128 |
+
[*Example 2*:
|
| 129 |
+
|
| 130 |
``` cpp
|
| 131 |
namespace M {
|
| 132 |
class B { };
|
| 133 |
}
|
| 134 |
```
|
|
|
|
| 148 |
// 3) scope of N::Y's base class M::B
|
| 149 |
// 4) scope of namespace N, before the definition of N::Y
|
| 150 |
// 5) global scope, before the definition of N
|
| 151 |
```
|
| 152 |
|
| 153 |
+
— *end example*]
|
| 154 |
+
|
| 155 |
+
[*Note 2*: When looking for a prior declaration of a class or function
|
| 156 |
+
introduced by a `friend` declaration, scopes outside of the innermost
|
| 157 |
+
enclosing namespace scope are not considered; see
|
| 158 |
+
[[namespace.memdef]]. — *end note*]
|
| 159 |
+
|
| 160 |
+
[*Note 3*: [[basic.scope.class]] further describes the restrictions on
|
| 161 |
+
the use of names in a class definition. [[class.nest]] further describes
|
| 162 |
+
the restrictions on the use of names in nested class definitions.
|
| 163 |
[[class.local]] further describes the restrictions on the use of names
|
| 164 |
+
in local class definitions. — *end note*]
|
| 165 |
|
| 166 |
For the members of a class `X`, a name used in a member function body,
|
| 167 |
+
in a default argument, in a *noexcept-specifier*, in the
|
| 168 |
*brace-or-equal-initializer* of a non-static data member (
|
| 169 |
[[class.mem]]), or in the definition of a class member outside of the
|
| 170 |
definition of `X`, following the member’s *declarator-id*[^7], shall be
|
| 171 |
declared in one of the following ways:
|
| 172 |
|
|
|
|
| 184 |
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 185 |
that is a member of `N`, or is a local class or a nested class within
|
| 186 |
a local class of a function that is a member of `N`, before the use of
|
| 187 |
the name, in namespace `N` or in one of `N`’s enclosing namespaces.
|
| 188 |
|
| 189 |
+
[*Example 3*:
|
| 190 |
+
|
| 191 |
``` cpp
|
| 192 |
class B { };
|
| 193 |
namespace M {
|
| 194 |
namespace N {
|
| 195 |
class X : public B {
|
|
|
|
| 208 |
// 4) scope of namespace M::N
|
| 209 |
// 5) scope of namespace M
|
| 210 |
// 6) global scope, before the definition of M::N::X::f
|
| 211 |
```
|
| 212 |
|
| 213 |
+
— *end example*]
|
| 214 |
+
|
| 215 |
+
[*Note 4*: [[class.mfct]] and [[class.static]] further describe the
|
| 216 |
+
restrictions on the use of names in member function definitions.
|
| 217 |
+
[[class.nest]] further describes the restrictions on the use of names in
|
| 218 |
+
the scope of nested classes. [[class.local]] further describes the
|
| 219 |
+
restrictions on the use of names in local class
|
| 220 |
+
definitions. — *end note*]
|
| 221 |
|
| 222 |
Name lookup for a name used in the definition of a `friend` function (
|
| 223 |
[[class.friend]]) defined inline in the class granting friendship shall
|
| 224 |
proceed as described for lookup in member function definitions. If the
|
| 225 |
`friend` function is not defined in the class granting friendship, name
|
|
|
|
| 232 |
class ([[class.member.lookup]]). If it is not found, or if the name is
|
| 233 |
part of a *template-argument* in the *declarator-id*, the look up is as
|
| 234 |
described for unqualified names in the definition of the class granting
|
| 235 |
friendship.
|
| 236 |
|
| 237 |
+
[*Example 4*:
|
| 238 |
+
|
| 239 |
``` cpp
|
| 240 |
struct A {
|
| 241 |
typedef int AT;
|
| 242 |
void f1(AT);
|
| 243 |
void f2(float);
|
|
|
|
| 250 |
friend void A::f2(BT); // parameter type is B::BT
|
| 251 |
friend void A::f3<AT>(); // template argument is B::AT
|
| 252 |
};
|
| 253 |
```
|
| 254 |
|
| 255 |
+
— *end example*]
|
| 256 |
+
|
| 257 |
During the lookup for a name used as a default argument (
|
| 258 |
[[dcl.fct.default]]) in a function *parameter-declaration-clause* or
|
| 259 |
used in the *expression* of a *mem-initializer* for a constructor (
|
| 260 |
[[class.base.init]]), the function parameter names are visible and hide
|
| 261 |
the names of entities declared in the block, class or namespace scopes
|
| 262 |
+
containing the function declaration.
|
| 263 |
+
|
| 264 |
+
[*Note 5*: [[dcl.fct.default]] further describes the restrictions on
|
| 265 |
+
the use of names in default arguments. [[class.base.init]] further
|
| 266 |
+
describes the restrictions on the use of names in a
|
| 267 |
+
*ctor-initializer*. — *end note*]
|
| 268 |
|
| 269 |
During the lookup of a name used in the *constant-expression* of an
|
| 270 |
*enumerator-definition*, previously declared *enumerator*s of the
|
| 271 |
enumeration are visible and hide the names of entities declared in the
|
| 272 |
block, class, or namespace scopes containing the *enum-specifier*.
|
| 273 |
|
| 274 |
A name used in the definition of a `static` data member of class `X` (
|
| 275 |
[[class.static.data]]) (after the *qualified-id* of the static member)
|
| 276 |
is looked up as if the name was used in a member function of `X`.
|
| 277 |
+
|
| 278 |
+
[*Note 6*: [[class.static.data]] further describes the restrictions on
|
| 279 |
+
the use of names in the definition of a `static` data
|
| 280 |
+
member. — *end note*]
|
| 281 |
|
| 282 |
If a variable member of a namespace is defined outside of the scope of
|
| 283 |
its namespace then any name that appears in the definition of the member
|
| 284 |
(after the *declarator-id*) is looked up as if the definition of the
|
| 285 |
member occurred in its namespace.
|
| 286 |
|
| 287 |
+
[*Example 5*:
|
| 288 |
+
|
| 289 |
``` cpp
|
| 290 |
namespace N {
|
| 291 |
int i = 4;
|
| 292 |
extern int j;
|
| 293 |
}
|
|
|
|
| 295 |
int i = 2;
|
| 296 |
|
| 297 |
int N::j = i; // N::j == 4
|
| 298 |
```
|
| 299 |
|
| 300 |
+
— *end example*]
|
| 301 |
+
|
| 302 |
A name used in the handler for a *function-try-block* (Clause
|
| 303 |
[[except]]) is looked up as if the name was used in the outermost block
|
| 304 |
of the function definition. In particular, the function parameter names
|
| 305 |
shall not be redeclared in the *exception-declaration* nor in the
|
| 306 |
outermost block of a handler for the *function-try-block*. Names
|
| 307 |
declared in the outermost block of the function definition are not found
|
| 308 |
when looked up in the scope of a handler for the *function-try-block*.
|
|
|
|
| 309 |
|
| 310 |
+
[*Note 7*: But function parameter names are found. — *end note*]
|
| 311 |
+
|
| 312 |
+
[*Note 8*: The rules for name lookup in template definitions are
|
| 313 |
+
described in [[temp.res]]. — *end note*]
|
| 314 |
|
| 315 |
### Argument-dependent name lookup <a id="basic.lookup.argdep">[[basic.lookup.argdep]]</a>
|
| 316 |
|
| 317 |
When the *postfix-expression* in a function call ([[expr.call]]) is an
|
| 318 |
*unqualified-id*, other namespaces not considered during the usual
|
|
|
|
| 321 |
declarations ([[class.friend]]) not otherwise visible may be found.
|
| 322 |
These modifications to the search depend on the types of the arguments
|
| 323 |
(and for template template arguments, the namespace of the template
|
| 324 |
argument).
|
| 325 |
|
| 326 |
+
[*Example 1*:
|
| 327 |
+
|
| 328 |
``` cpp
|
| 329 |
namespace N {
|
| 330 |
struct S { };
|
| 331 |
void f(S);
|
| 332 |
}
|
| 333 |
|
| 334 |
void g() {
|
| 335 |
N::S s;
|
| 336 |
f(s); // OK: calls N::f
|
| 337 |
+
(f)(s); // error: N::f not considered; parentheses prevent argument-dependent lookup
|
|
|
|
| 338 |
}
|
| 339 |
```
|
| 340 |
|
| 341 |
+
— *end example*]
|
| 342 |
+
|
| 343 |
For each argument type `T` in the function call, there is a set of zero
|
| 344 |
+
or more *associated namespaces* and a set of zero or more *associated
|
| 345 |
+
classes* to be considered. The sets of namespaces and classes are
|
| 346 |
determined entirely by the types of the function arguments (and the
|
| 347 |
namespace of any template template argument). Typedef names and
|
| 348 |
*using-declaration*s used to specify the types do not contribute to this
|
| 349 |
set. The sets of namespaces and classes are determined in the following
|
| 350 |
way:
|
|
|
|
| 359 |
and classes also include: the namespaces and classes associated with
|
| 360 |
the types of the template arguments provided for template type
|
| 361 |
parameters (excluding template template parameters); the namespaces of
|
| 362 |
which any template template arguments are members; and the classes of
|
| 363 |
which any member templates used as template template arguments are
|
| 364 |
+
members. \[*Note 1*: Non-type template arguments do not contribute to
|
| 365 |
+
the set of associated namespaces. — *end note*]
|
| 366 |
- If `T` is an enumeration type, its associated namespace is the
|
| 367 |
innermost enclosing namespace of its declaration. If it is a class
|
| 368 |
member, its associated class is the member’s class; else it has no
|
| 369 |
associated class.
|
| 370 |
- If `T` is a pointer to `U` or an array of `U`, its associated
|
|
|
|
| 397 |
argument dependent lookup (defined as follows). If *X* contains
|
| 398 |
|
| 399 |
- a declaration of a class member, or
|
| 400 |
- a block-scope function declaration that is not a *using-declaration*,
|
| 401 |
or
|
| 402 |
+
- a declaration that is neither a function nor a function template
|
| 403 |
|
| 404 |
then *Y* is empty. Otherwise *Y* is the set of declarations found in the
|
| 405 |
namespaces associated with the argument types as described below. The
|
| 406 |
set of declarations found by the lookup of the name is the union of *X*
|
| 407 |
+
and *Y*.
|
| 408 |
+
|
| 409 |
+
[*Note 2*: The namespaces and classes associated with the argument
|
| 410 |
+
types can include namespaces and classes already considered by the
|
| 411 |
+
ordinary unqualified lookup. — *end note*]
|
| 412 |
+
|
| 413 |
+
[*Example 2*:
|
| 414 |
|
| 415 |
``` cpp
|
| 416 |
namespace NS {
|
| 417 |
class T { };
|
| 418 |
void f(T);
|
|
|
|
| 425 |
extern void g(NS::T, float);
|
| 426 |
g(parm, 1); // OK: calls g(NS::T, float)
|
| 427 |
}
|
| 428 |
```
|
| 429 |
|
| 430 |
+
— *end example*]
|
| 431 |
+
|
| 432 |
When considering an associated namespace, the lookup is the same as the
|
| 433 |
lookup performed when the associated namespace is used as a qualifier (
|
| 434 |
[[namespace.qual]]) except that:
|
| 435 |
|
| 436 |
- Any *using-directive*s in the associated namespace are ignored.
|
|
|
|
| 451 |
lookup of the name preceding that `::` considers only namespaces, types,
|
| 452 |
and templates whose specializations are types. If the name found does
|
| 453 |
not designate a namespace or a class, enumeration, or dependent type,
|
| 454 |
the program is ill-formed.
|
| 455 |
|
| 456 |
+
[*Example 1*:
|
| 457 |
+
|
| 458 |
``` cpp
|
| 459 |
class A {
|
| 460 |
public:
|
| 461 |
static int n;
|
| 462 |
};
|
|
|
|
| 465 |
A::n = 42; // OK
|
| 466 |
A b; // ill-formed: A does not name a type
|
| 467 |
}
|
| 468 |
```
|
| 469 |
|
| 470 |
+
— *end example*]
|
| 471 |
+
|
| 472 |
+
[*Note 1*: Multiply qualified names, such as `N1::N2::N3::n`, can be
|
| 473 |
+
used to refer to members of nested classes ([[class.nest]]) or members
|
| 474 |
+
of nested namespaces. — *end note*]
|
| 475 |
|
| 476 |
In a declaration in which the *declarator-id* is a *qualified-id*, names
|
| 477 |
used before the *qualified-id* being declared are looked up in the
|
| 478 |
defining namespace scope; names following the *qualified-id* are looked
|
| 479 |
up in the scope of the member’s class or namespace.
|
| 480 |
|
| 481 |
+
[*Example 2*:
|
| 482 |
+
|
| 483 |
``` cpp
|
| 484 |
class X { };
|
| 485 |
class C {
|
| 486 |
class X { };
|
| 487 |
static const int number = 50;
|
| 488 |
static X arr[number];
|
| 489 |
};
|
| 490 |
X C::arr[number]; // ill-formed:
|
| 491 |
+
// equivalent to ::X C::arr[C::number];
|
| 492 |
+
// and not to C::X C::arr[C::number];
|
| 493 |
```
|
| 494 |
|
| 495 |
+
— *end example*]
|
| 496 |
+
|
| 497 |
A name prefixed by the unary scope operator `::` ([[expr.prim]]) is
|
| 498 |
looked up in global scope, in the translation unit where it is used. The
|
| 499 |
name shall be declared in global namespace scope or shall be a name
|
| 500 |
whose declaration is visible in global scope because of a
|
| 501 |
*using-directive* ([[namespace.qual]]). The use of `::` allows a global
|
|
|
|
| 514 |
nested-name-specifierₒₚₜ class-name '::' '~' class-name
|
| 515 |
```
|
| 516 |
|
| 517 |
the second *class-name* is looked up in the same scope as the first.
|
| 518 |
|
| 519 |
+
[*Example 3*:
|
| 520 |
+
|
| 521 |
``` cpp
|
| 522 |
struct C {
|
| 523 |
typedef int I;
|
| 524 |
};
|
| 525 |
typedef int I1, I2;
|
| 526 |
extern int* p;
|
| 527 |
extern int* q;
|
| 528 |
p->C::I::~I(); // I is looked up in the scope of C
|
| 529 |
+
q->I1::~I2(); // I2 is looked up in the scope of the postfix-expression
|
|
|
|
| 530 |
|
| 531 |
struct A {
|
| 532 |
~A();
|
| 533 |
};
|
| 534 |
typedef A AB;
|
|
|
|
| 536 |
AB* p;
|
| 537 |
p->AB::~AB(); // explicitly calls the destructor for A
|
| 538 |
}
|
| 539 |
```
|
| 540 |
|
| 541 |
+
— *end example*]
|
| 542 |
+
|
| 543 |
+
[*Note 2*: [[basic.lookup.classref]] describes how name lookup
|
| 544 |
+
proceeds after the `.` and `->` operators. — *end note*]
|
| 545 |
|
| 546 |
#### Class members <a id="class.qual">[[class.qual]]</a>
|
| 547 |
|
| 548 |
If the *nested-name-specifier* of a *qualified-id* nominates a class,
|
| 549 |
the name specified after the *nested-name-specifier* is looked up in the
|
| 550 |
scope of the class ([[class.member.lookup]]), except for the cases
|
| 551 |
listed below. The name shall represent one or more members of that class
|
| 552 |
+
or of one of its base classes (Clause [[class.derived]]).
|
|
|
|
|
|
|
|
|
|
| 553 |
|
| 554 |
+
[*Note 1*: A class member can be referred to using a *qualified-id* at
|
| 555 |
+
any point in its potential scope (
|
| 556 |
+
[[basic.scope.class]]). — *end note*]
|
| 557 |
+
|
| 558 |
+
The exceptions to the name lookup rule above are the following:
|
| 559 |
+
|
| 560 |
+
- the lookup for a destructor is as specified in [[basic.lookup.qual]];
|
| 561 |
- a *conversion-type-id* of a *conversion-function-id* is looked up in
|
| 562 |
the same manner as a *conversion-type-id* in a class member access
|
| 563 |
(see [[basic.lookup.classref]]);
|
| 564 |
- the names in a *template-argument* of a *template-id* are looked up in
|
| 565 |
the context in which the entire *postfix-expression* occurs.
|
|
|
|
| 570 |
In a lookup in which function names are not ignored[^9] and the
|
| 571 |
*nested-name-specifier* nominates a class `C`:
|
| 572 |
|
| 573 |
- if the name specified after the *nested-name-specifier*, when looked
|
| 574 |
up in `C`, is the injected-class-name of `C` (Clause [[class]]), or
|
| 575 |
+
- in a *using-declarator* of a *using-declaration* (
|
| 576 |
+
[[namespace.udecl]]) that is a *member-declaration*, if the name
|
| 577 |
+
specified after the *nested-name-specifier* is the same as the
|
| 578 |
+
*identifier* or the *simple-template-id*’s *template-name* in the last
|
| 579 |
+
component of the *nested-name-specifier*,
|
| 580 |
+
|
| 581 |
+
the name is instead considered to name the constructor of class `C`.
|
| 582 |
+
|
| 583 |
+
[*Note 2*: For example, the constructor is not an acceptable lookup
|
| 584 |
+
result in an *elaborated-type-specifier* so the constructor would not be
|
| 585 |
+
used in place of the injected-class-name. — *end note*]
|
| 586 |
+
|
| 587 |
+
Such a constructor name shall be used only in the *declarator-id* of a
|
| 588 |
+
declaration that names a constructor or in a *using-declaration*.
|
| 589 |
+
|
| 590 |
+
[*Example 1*:
|
| 591 |
|
| 592 |
``` cpp
|
| 593 |
struct A { A(); };
|
| 594 |
struct B: public A { B(); };
|
| 595 |
|
|
|
|
| 599 |
B::A ba; // object of type A
|
| 600 |
A::A a; // error, A::A is not a type name
|
| 601 |
struct A::A a2; // object of type A
|
| 602 |
```
|
| 603 |
|
| 604 |
+
— *end example*]
|
| 605 |
+
|
| 606 |
A class member name hidden by a name in a nested declarative region or
|
| 607 |
by the name of a derived class member can still be found if qualified by
|
| 608 |
the name of its class followed by the `::` operator.
|
| 609 |
|
| 610 |
#### Namespace members <a id="namespace.qual">[[namespace.qual]]</a>
|
| 611 |
|
| 612 |
+
If the *nested-name-specifier* of a *qualified-id* nominates a namespace
|
| 613 |
+
(including the case where the *nested-name-specifier* is `::`, i.e.,
|
| 614 |
+
nominating the global namespace), the name specified after the
|
| 615 |
+
*nested-name-specifier* is looked up in the scope of the namespace. The
|
| 616 |
+
names in a *template-argument* of a *template-id* are looked up in the
|
| 617 |
+
context in which the entire *postfix-expression* occurs.
|
|
|
|
| 618 |
|
| 619 |
For a namespace `X` and name `m`, the namespace-qualified lookup set
|
| 620 |
S(X, m) is defined as follows: Let S'(X, m) be the set of all
|
| 621 |
declarations of `m` in `X` and the inline namespace set of `X` (
|
| 622 |
[[namespace.def]]). If S'(X, m) is not empty, S(X, m) is S'(X, m);
|
| 623 |
otherwise, S(X, m) is the union of S(Nᵢ, m) for all namespaces Nᵢ
|
| 624 |
+
nominated by *using-directive*s in `X` and its inline namespace set.
|
| 625 |
|
| 626 |
Given `X::m` (where `X` is a user-declared namespace), or given `::m`
|
| 627 |
(where X is the global namespace), if S(X, m) is the empty set, the
|
| 628 |
program is ill-formed. Otherwise, if S(X, m) has exactly one member, or
|
| 629 |
if the context of the reference is a *using-declaration* (
|
| 630 |
[[namespace.udecl]]), S(X, m) is the required set of declarations of
|
| 631 |
`m`. Otherwise if the use of `m` is not one that allows a unique
|
| 632 |
declaration to be chosen from S(X, m), the program is ill-formed.
|
| 633 |
|
| 634 |
+
[*Example 1*:
|
| 635 |
+
|
| 636 |
``` cpp
|
| 637 |
int x;
|
| 638 |
namespace Y {
|
| 639 |
void f(float);
|
| 640 |
void h(int);
|
|
|
|
| 663 |
void g();
|
| 664 |
}
|
| 665 |
|
| 666 |
void h()
|
| 667 |
{
|
| 668 |
+
AB::g(); // g is declared directly in AB, therefore S is { `AB::g()` } and AB::g() is chosen
|
| 669 |
+
|
| 670 |
+
AB::f(1); // f is not declared directly in AB so the rules are applied recursively to A and B;
|
| 671 |
+
// namespace Y is not searched and Y::f(float) is not considered;
|
| 672 |
+
// S is { `A::f(int)`, `B::f(char)` } and overload resolution chooses A::f(int)
|
| 673 |
+
|
|
|
|
|
|
|
| 674 |
AB::f('c'); // as above but resolution chooses B::f(char)
|
| 675 |
|
| 676 |
+
AB::x++; // x is not declared directly in AB, and is not declared in A or B, so the rules
|
| 677 |
+
// are applied recursively to Y and Z, S is { } so the program is ill-formed
|
| 678 |
+
|
| 679 |
+
AB::i++; // i is not declared directly in AB so the rules are applied recursively to A and B,
|
| 680 |
+
// S is { `A::i`, `B::i` } so the use is ambiguous and the program is ill-formed
|
| 681 |
+
|
| 682 |
+
AB::h(16.8); // h is not declared directly in AB and not declared directly in A or B so the rules
|
| 683 |
+
// are applied recursively to Y and Z, S is { `Y::h(int)`, `Z::h(double)` } and
|
| 684 |
+
// overload resolution chooses Z::h(double)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 685 |
}
|
| 686 |
```
|
| 687 |
|
| 688 |
+
— *end example*]
|
| 689 |
+
|
| 690 |
+
[*Note 1*:
|
| 691 |
+
|
| 692 |
The same declaration found more than once is not an ambiguity (because
|
| 693 |
+
it is still a unique declaration).
|
| 694 |
+
|
| 695 |
+
[*Example 2*:
|
| 696 |
|
| 697 |
``` cpp
|
| 698 |
namespace A {
|
| 699 |
int a;
|
| 700 |
}
|
|
|
|
| 712 |
using namespace C;
|
| 713 |
}
|
| 714 |
|
| 715 |
void f()
|
| 716 |
{
|
| 717 |
+
BC::a++; // OK: S is { `A::a`, `A::a` }
|
| 718 |
}
|
| 719 |
|
| 720 |
namespace D {
|
| 721 |
using A::a;
|
| 722 |
}
|
|
|
|
| 726 |
using namespace D;
|
| 727 |
}
|
| 728 |
|
| 729 |
void g()
|
| 730 |
{
|
| 731 |
+
BD::a++; // OK: S is { `A::a`, `A::a` }
|
| 732 |
}
|
| 733 |
```
|
| 734 |
|
| 735 |
+
— *end example*]
|
| 736 |
+
|
| 737 |
+
— *end note*]
|
| 738 |
+
|
| 739 |
+
[*Example 3*:
|
| 740 |
+
|
| 741 |
Because each referenced namespace is searched at most once, the
|
| 742 |
following is well-defined:
|
| 743 |
|
| 744 |
``` cpp
|
| 745 |
namespace B {
|
|
|
|
| 755 |
using namespace A;
|
| 756 |
}
|
| 757 |
|
| 758 |
void f()
|
| 759 |
{
|
| 760 |
+
A::a++; // OK: a declared directly in A, S is { `A::a` }
|
| 761 |
+
B::a++; // OK: both A and B searched (once), S is { `A::a` }
|
| 762 |
+
A::b++; // OK: both A and B searched (once), S is { `B::b` }
|
| 763 |
+
B::b++; // OK: b declared directly in B, S is { `B::b` }
|
| 764 |
}
|
| 765 |
```
|
| 766 |
|
| 767 |
+
— *end example*]
|
| 768 |
+
|
| 769 |
During the lookup of a qualified namespace member name, if the lookup
|
| 770 |
finds more than one declaration of the member, and if one declaration
|
| 771 |
introduces a class name or enumeration name and the other declarations
|
| 772 |
either introduce the same variable, the same enumerator or a set of
|
| 773 |
functions, the non-type name hides the class or enumeration name if and
|
| 774 |
only if the declarations are from the same namespace; otherwise (the
|
| 775 |
declarations are from different namespaces), the program is ill-formed.
|
| 776 |
|
| 777 |
+
[*Example 4*:
|
| 778 |
+
|
| 779 |
``` cpp
|
| 780 |
namespace A {
|
| 781 |
struct x { };
|
| 782 |
int x;
|
| 783 |
int y;
|
|
|
|
| 793 |
int i = C::x; // OK, A::x (of type int)
|
| 794 |
int j = C::y; // ambiguous, A::y or B::y
|
| 795 |
}
|
| 796 |
```
|
| 797 |
|
| 798 |
+
— *end example*]
|
| 799 |
+
|
| 800 |
In a declaration for a namespace member in which the *declarator-id* is
|
| 801 |
a *qualified-id*, given that the *qualified-id* for the namespace member
|
| 802 |
has the form
|
| 803 |
|
| 804 |
``` bnf
|
|
|
|
| 807 |
|
| 808 |
the *unqualified-id* shall name a member of the namespace designated by
|
| 809 |
the *nested-name-specifier* or of an element of the inline namespace
|
| 810 |
set ([[namespace.def]]) of that namespace.
|
| 811 |
|
| 812 |
+
[*Example 5*:
|
| 813 |
+
|
| 814 |
``` cpp
|
| 815 |
namespace A {
|
| 816 |
namespace B {
|
| 817 |
void f1(int);
|
| 818 |
}
|
| 819 |
using namespace B;
|
| 820 |
}
|
| 821 |
void A::f1(int){ } // ill-formed, f1 is not a member of A
|
| 822 |
```
|
| 823 |
|
| 824 |
+
— *end example*]
|
| 825 |
+
|
| 826 |
However, in such namespace member declarations, the
|
| 827 |
*nested-name-specifier* may rely on *using-directive*s to implicitly
|
| 828 |
provide the initial part of the *nested-name-specifier*.
|
| 829 |
|
| 830 |
+
[*Example 6*:
|
| 831 |
+
|
| 832 |
``` cpp
|
| 833 |
namespace A {
|
| 834 |
namespace B {
|
| 835 |
void f1(int);
|
| 836 |
}
|
|
|
|
| 845 |
using namespace A;
|
| 846 |
using namespace C::D;
|
| 847 |
void B::f1(int){ } // OK, defines A::B::f1(int)
|
| 848 |
```
|
| 849 |
|
| 850 |
+
— *end example*]
|
| 851 |
+
|
| 852 |
### Elaborated type specifiers <a id="basic.lookup.elab">[[basic.lookup.elab]]</a>
|
| 853 |
|
| 854 |
An *elaborated-type-specifier* ([[dcl.type.elab]]) may be used to refer
|
| 855 |
to a previously declared *class-name* or *enum-name* even though the
|
| 856 |
name has been hidden by a non-type declaration (
|
|
|
|
| 884 |
qualified name lookup is performed, as described in
|
| 885 |
[[basic.lookup.qual]], but ignoring any non-type names that have been
|
| 886 |
declared. If the name lookup does not find a previously declared
|
| 887 |
*type-name*, the *elaborated-type-specifier* is ill-formed.
|
| 888 |
|
| 889 |
+
[*Example 1*:
|
| 890 |
+
|
| 891 |
``` cpp
|
| 892 |
struct Node {
|
| 893 |
struct Node* Next; // OK: Refers to Node at global scope
|
| 894 |
struct Data* Data; // OK: Declares type Data
|
| 895 |
// at global scope and member Data
|
| 896 |
};
|
| 897 |
|
| 898 |
struct Data {
|
| 899 |
struct Node* Node; // OK: Refers to Node at global scope
|
| 900 |
+
friend struct ::Glob; // error: Glob is not declared, cannot introduce a qualified type~([dcl.type.elab])
|
| 901 |
+
friend struct Glob; // OK: Refers to (as yet) undeclared Glob at global scope.
|
| 902 |
+
...
|
|
|
|
|
|
|
| 903 |
};
|
| 904 |
|
| 905 |
struct Base {
|
| 906 |
struct Data; // OK: Declares nested Data
|
| 907 |
struct ::Data* thatData; // OK: Refers to ::Data
|
| 908 |
struct Base::Data* thisData; // OK: Refers to nested Data
|
| 909 |
friend class ::Data; // OK: global Data is a friend
|
| 910 |
friend class Data; // OK: nested Data is a friend
|
| 911 |
+
struct Data { ... }; // Defines nested Data
|
| 912 |
};
|
| 913 |
|
| 914 |
struct Data; // OK: Redeclares Data at global scope
|
| 915 |
struct ::Data; // error: cannot introduce a qualified type~([dcl.type.elab])
|
| 916 |
struct Base::Data; // error: cannot introduce a qualified type~([dcl.type.elab])
|
| 917 |
struct Base::Datum; // error: Datum undefined
|
| 918 |
struct Base::Data* pBase; // OK: refers to nested Data
|
| 919 |
```
|
| 920 |
|
| 921 |
+
— *end example*]
|
| 922 |
+
|
| 923 |
### Class member access <a id="basic.lookup.classref">[[basic.lookup.classref]]</a>
|
| 924 |
|
| 925 |
In a class member access expression ([[expr.ref]]), if the `.` or `->`
|
| 926 |
token is immediately followed by an *identifier* followed by a `<`, the
|
| 927 |
identifier must be looked up to determine whether the `<` is the
|
|
|
|
| 939 |
|
| 940 |
If the *unqualified-id* is `~`*type-name*, the *type-name* is looked up
|
| 941 |
in the context of the entire *postfix-expression*. If the type `T` of
|
| 942 |
the object expression is of a class type `C`, the *type-name* is also
|
| 943 |
looked up in the scope of class `C`. At least one of the lookups shall
|
| 944 |
+
find a name that refers to cv `T`.
|
| 945 |
+
|
| 946 |
+
[*Example 1*:
|
| 947 |
|
| 948 |
``` cpp
|
| 949 |
struct A { };
|
| 950 |
|
| 951 |
struct B {
|
|
|
|
| 956 |
void B::f(::A* a) {
|
| 957 |
a->~A(); // OK: lookup in *a finds the injected-class-name
|
| 958 |
}
|
| 959 |
```
|
| 960 |
|
| 961 |
+
— *end example*]
|
| 962 |
+
|
| 963 |
If the *id-expression* in a class member access is a *qualified-id* of
|
| 964 |
the form
|
| 965 |
|
| 966 |
+
``` cpp
|
| 967 |
+
class-name-or-namespace-name::...
|
| 968 |
+
```
|
| 969 |
+
|
| 970 |
the *class-name-or-namespace-name* following the `.` or `->` operator is
|
| 971 |
first looked up in the class of the object expression and the name, if
|
| 972 |
found, is used. Otherwise it is looked up in the context of the entire
|
| 973 |
+
*postfix-expression*.
|
| 974 |
+
|
| 975 |
+
[*Note 1*: See [[basic.lookup.qual]], which describes the lookup of a
|
| 976 |
+
name before `::`, which will only find a type or namespace
|
| 977 |
+
name. — *end note*]
|
| 978 |
|
| 979 |
If the *qualified-id* has the form
|
| 980 |
|
| 981 |
+
``` cpp
|
| 982 |
+
::class-name-or-namespace-name::...
|
| 983 |
+
```
|
| 984 |
+
|
| 985 |
the *class-name-or-namespace-name* is looked up in global scope as a
|
| 986 |
*class-name* or *namespace-name*.
|
| 987 |
|
| 988 |
If the *nested-name-specifier* contains a *simple-template-id* (
|
| 989 |
[[temp.names]]), the names in its *template-argument*s are looked up in
|
|
|
|
| 994 |
expression and the name, if found, is used. Otherwise it is looked up in
|
| 995 |
the context of the entire *postfix-expression*. In each of these
|
| 996 |
lookups, only names that denote types or templates whose specializations
|
| 997 |
are types are considered.
|
| 998 |
|
| 999 |
+
[*Example 2*:
|
| 1000 |
+
|
| 1001 |
``` cpp
|
| 1002 |
struct A { };
|
| 1003 |
namespace N {
|
| 1004 |
struct A {
|
| 1005 |
void g() { }
|
|
|
|
| 1011 |
N::A a;
|
| 1012 |
a.operator A(); // calls N::A::operator N::A
|
| 1013 |
}
|
| 1014 |
```
|
| 1015 |
|
| 1016 |
+
— *end example*]
|
| 1017 |
+
|
| 1018 |
### Using-directives and namespace aliases <a id="basic.lookup.udir">[[basic.lookup.udir]]</a>
|
| 1019 |
|
| 1020 |
In a *using-directive* or *namespace-alias-definition*, during the
|
| 1021 |
lookup for a *namespace-name* or for a name in a *nested-name-specifier*
|
| 1022 |
only namespace names are considered.
|