[basic.lookup.classref] (original) (raw)
6 Basics [basic]
6.5 Name lookup [basic.lookup]
6.5.5 Class member access [basic.lookup.classref]
In a class member access expression, if the .or -> token is immediately followed by an identifierfollowed by a <, the identifier must be looked up to determine whether the < is the beginning of a template argument list ([temp.names]) or a less-than operator.
The identifier is first looked up in the class of the object expression ([class.member.lookup]).
If the identifier is not found, it is then looked up in the context of the entirepostfix-expression and shall name a template whose specializations are types.
If the type T of the object expression is of a class type C, the type-name is also looked up in the scope of class C.
At least one of the lookups shall find a name that refers to cv T.
[ Example
:
struct A { };
struct B { struct A { }; void f(::A* a); };
void B::f(::A* a) { a->~A(); // OK: lookup in *a finds the injected-class-name }
— end example
]
If the id-expression in a class member access is aqualified-id of the form
class-name-or-namespace-name::...
the class-name-or-namespace-name following the . or-> operator is first looked up in the class of the object expression ([class.member.lookup]) and the name, if found, is used.
Otherwise it is looked up in the context of the entirepostfix-expression.
[ Note
:
See [basic.lookup.qual], which describes the lookup of a name before ::, which will only find a type or namespace name.
— end note
]
Otherwise it is looked up in the context of the entire postfix-expression.
In each of these lookups, only names that denote types or templates whose specializations are types are considered.
[ Example
:
struct A { }; namespace N { struct A { void g() { } template operator T(); }; }
int main() { N::A a; a.operator A(); // calls N::A::operator N::A }
— end example
]