[basic.lookup.qual] (original) (raw)

6.5.5.1 General [basic.lookup.qual.general]

Lookup of an identifierfollowed by a ​::​ scope resolution operator considers only namespaces, types, and templates whose specializations are types.

[Example 1: class A { public: static int n;};int main() { int A; A::n = 42; A b; } template<int> struct B : A {};namespace N { template<int> void B();int f() { return B<0>::n; } } — _end example_]

A qualified name is

The lookup context of a member-qualified name is the type of its associated object expression (considered dependent if the object expression is type-dependent).

The lookup context of any other qualified name is the type, template, or namespace nominated by the preceding nested-name-specifier.

[Note 1:

When parsing a class member access, the name following the -> or . is a qualified name even though it is not yet known of which kind.

— _end note_]

[Example 2:

In N::C::m.Base::f() Base is a member-qualified name; the other qualified names are C, m, and f.

— _end example_]

Qualified name lookupin a class, namespace, or enumeration performs a search of the scope associated with it ([class.member.lookup]) except as specified below.

Unless otherwise specified, a qualified name undergoes qualified name lookup in its lookup context from the point where it appears unless the lookup context either is dependent and is not the current instantiation ([temp.dep.type]) or is not a class or class template.

If nothing is found by qualified lookup for a member-qualified name that is the terminal name ([expr.prim.id.unqual]) of a nested-name-specifier and is not dependent, it undergoes unqualified lookup.

[Note 2:

During lookup for a template specialization, no names are dependent.

— _end note_]

[Example 3: int f();struct A { int B, C;template<int> using D = void;using T = void;void f();};using B = A;template<int> using C = A;template<int> using D = A;template<int> using X = A;template<class T> void g(T *p) { p->X<0>::f(); p->template X<0>::f(); p->B::f(); p->template C<0>::f(); p->template D<0>::f(); p->T::f(); } template void g(A*); — _end example_]

If a qualified name Q follows a ~:

[Example 4: struct C { typedef int I;};typedef int I1, I2;extern int* p;extern int* q;void f() { p->C::I::~I(); q->I1::~I2(); } struct A { ~A();};typedef A AB;int main() { AB* p; p->AB::~AB(); } — _end example_]

6.5.5.2 Class members [class.qual]

In a lookup for a qualified name N whose lookup context is a class Cin which function names are not ignored,18

N is instead considered to name the constructor of class C.

Such a constructor name shall be used only in the declarator-id of a (friend) declaration of a constructor or in a using-declaration.

[Example 1: struct A { A(); };struct B: public A { B(); }; A::A() { }B::B() { }B::A ba; A::A a; struct A::A a2; — _end example_]

6.5.5.3 Namespace members [namespace.qual]

Qualified name lookup in a namespace N additionally searches every element of the inline namespace set of N ([namespace.def]).

If nothing is found, the results of the lookup are the results of qualified name lookup in each namespace nominated by a using-directivethat precedes the point of the lookup and inhabits N or an element of N's inline namespace set.

[Note 1:

If a using-directive refers to a namespace that has already been considered, it does not affect the result.

— _end note_]

[Example 1: int x;namespace Y { void f(float);void h(int);} namespace Z { void h(double);} namespace A { using namespace Y;void f(int);void g(int);int i;} namespace B { using namespace Z;void f(char);int i;} namespace AB { using namespace A;using namespace B;void g();} void h() { AB::g(); AB::f(1); AB::f('c'); AB::x++; AB::i++; AB::h(16.8); } — _end example_]

[Note 2:

The same declaration found more than once is not an ambiguity (because it is still a unique declaration).

[Example 2: namespace A { int a;} namespace B { using namespace A;} namespace C { using namespace A;} namespace BC { using namespace B;using namespace C;} void f() { BC::a++; } namespace D { using A::a;} namespace BD { using namespace B;using namespace D;} void g() { BD::a++; } — _end example_]

— _end note_]

[Example 3:

Because each referenced namespace is searched at most once, the following is well-defined:namespace B { int b;} namespace A { using namespace B;int a;} namespace B { using namespace A;} void f() { A::a++; B::a++; A::b++; B::b++; }

— _end example_]

[Note 3:

Class and enumeration declarations are not discarded because of other declarations found in other searches.

— _end note_]

[Example 4: namespace A { struct x { };int x;int y;} namespace B { struct y { };} namespace C { using namespace A;using namespace B;int i = C::x; int j = C::y; } — _end example_]