Should name lookup be deferred for a dependent class/namespace-name in a
class-member-access expression?
The following code is rejected by both clang and gcc, but accepted by ICC
(and MSVC, but that's not saying much.)
template<typename T>
void f(T t)
{
t.Dependent::f(); // clang accepts, gcc rejects
t.operator Dependent(); // both reject
}
My reading of the standard suggests expressions should be accepted.
In the first case, Dependent is a type or namespace name. In the second
case, Dependent is a type name.
In both cases, the name Dependent is to be "looked up in the class of the
[dependent] object expression" t, and therefore the lookup should be
deferred until the template is instantiated.
Is there something I'm missing?
Relevant quotes from C++ Working Draft N3337:
3.4.5 Class member access [basic.lookup.classref]
If the id-expression in a class member access is a qualified-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 and the name, if found, is used. Otherwise it is looked
up in the context of the entire postfix-expression. [ Note: See 3.4.3,
which describes the lookup of a name before ::, which will only find a
type or namespace name. —end note ]
If the id-expression is a conversion-function-id, its conversion-type-id
is first looked up in the class of the object expression and the name, if
found, is used. 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.
14.6.2 Dependent names [temp.dep]
Inside a template, some constructs have semantics which may differ from
one instantiation to another. Such a construct depends on the template
parameters. In particular, types and expressions may depend on the type
and/or value of template parameters (as determined by the template
arguments) and this determines the context for name lookup for certain
names. Expressions may be type-dependent (on the type of a template
parameter) or value-dependent (on the value of a non-type template
parameter).
[...]
Such names are unbound and are looked up at the point of the template
instantiation (14.6.4.1) in both the context of the template definition
and the context of the point of instantiation.
No comments:
Post a Comment