<div class="gmail_quote">On Wed, Apr 4, 2012 at 5:35 AM, Bruce Merry <span dir="ltr"><<a href="mailto:bmerry@gmail.com">bmerry@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi<br>
<br>
With reference to <a href="http://clang.llvm.org/compatibility.html#dep_lookup" target="_blank">http://clang.llvm.org/compatibility.html#dep_lookup</a>:<br>
I've just run into exactly the problem with overloaded operator<< that<br>
this page describes. I've modified my code as suggested, but out of<br>
interest I'm curious as to why the unqualified lookup on dependent<br>
names is done immediately rather than deferred until template<br>
instantiation (when the argument-dependent lookup is done). It seems<br>
to contradict the C++11 spec 14.6.2 (it looks like C++98 has the same<br>
language as well), which says:<br>
<br>
"If an operand of an operator is a type-dependent expression, the<br>
operator also denotes a dependent name. Such names are unbound and are<br>
looked up at the point of the template instantiation (14.6.4.1) in<br>
both the context of the template definition and the context of the<br>
point of instantiation."<br>
<br>
In the example at the URL above, std::cout<<value has a second<br>
argument which is type-dependent, so I would expect operator<< to be<br>
looked up in the context of the point of instantiation, at which point<br>
the appropriate overload is defined.</blockquote><div><br></div><div>Notionally, yes, name lookup occurs at the point of instantiation. But that doesn't mean that name lookup finds names which have been declared since the template was defined. The relevant section is <a href="http://14.6.4.2">14.6.4.2</a>:</div>
<div><br></div><div>"For a function call that depends on a template parameter, the candidate functions are found using the usual</div><div>lookup rules (3.4.1, 3.4.2, 3.4.3) except that:</div><div>— For the part of the lookup using unqualified name lookup (3.4.1) or qualified name lookup (3.4.3), only</div>
<div>function declarations from the template definition context are found.</div><div>— For the part of the lookup using associated namespaces (3.4.2), only function declarations found in</div><div>either the template definition context or the template instantiation context are found."</div>
</div>