<br><br><div class="gmail_quote">Le 4 avril 2012 14:35, Bruce Merry <span dir="ltr"><<a href="mailto:bmerry@gmail.com">bmerry@gmail.com</a>></span> a écrit :<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.<br>
<br>
Thanks<br>
<span class="HOEnZb"><font color="#888888">Bruce<br>
--<br>
Dr Bruce Merry<br>
bmerry <@> gmail <.> com<br>
<a href="http://www.brucemerry.org.za/" target="_blank">http://www.brucemerry.org.za/</a><br>
<a href="http://blog.brucemerry.org.za/" target="_blank">http://blog.brucemerry.org.za/</a><br>
</font></span></blockquote><div><br>Ah, this one is amusing.<br><br>Actually, overload resolution is *done* at the point of instantiation.<br><br>However, for the template code to be valid, the name should exist at the point where the template is declared...<br>
<br>In the URL mentionned, you could perfectly declare:<br><br><div style="margin-left:40px">struct Useless; Useless Multiply(Useless, Useless);<br><br></div>Prior to the template and it would suffice to appease the compiler. No definition of either Useless or its Multiply would be needed because they will not be used in the end.<br>
<br>I sometimes wonder if this was done to "secure" the template instantiation by guaranteeing that at least one overload exist (even if not suitable, we cannot know at this point), rather than say... an object of that name.<br>
<br>-- Matthieu<br></div></div><br>