[cfe-dev] Explaining unqualified lookup in templates
dgregor at apple.com
Wed Apr 4 10:28:32 PDT 2012
On Apr 4, 2012, at 5:35 AM, Bruce Merry <bmerry at gmail.com> wrote:
> With reference to http://clang.llvm.org/compatibility.html#dep_lookup:
> I've just run into exactly the problem with overloaded operator<< that
> this page describes. I've modified my code as suggested, but out of
> interest I'm curious as to why the unqualified lookup on dependent
> names is done immediately rather than deferred until template
> instantiation (when the argument-dependent lookup is done). It seems
> to contradict the C++11 spec 14.6.2 (it looks like C++98 has the same
> language as well), which says:
> "If an operand of an operator is a type-dependent expression, the
> operator also denotes a dependent name. Such names are unbound and are
> looked up at the point of the template instantiation (184.108.40.206) in
> both the context of the template definition and the context of the
> point of instantiation."
> In the example at the URL above, std::cout<<value has a second
> argument which is type-dependent, so I would expect operator<< to be
> looked up in the context of the point of instantiation, at which point
> the appropriate overload is defined.
The text you've quoted is rather imprecise about exactly what kinds of lookups are performed at each time.The lookup in the context of the template definition is unqualified name lookup + argument-dependent name lookup. The lookup in the context of the point of instantiation is only argument-dependent lookup.
More information about the cfe-dev