<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jun 4, 2015 at 1:09 PM, János Hack <span dir="ltr"><<a href="mailto:hjjohny@gmail.com" target="_blank">hjjohny@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi all,<br></div>Please consider this example:<br><br><br>template<typename T><br>struct vec{};<br><br>namespace std<br>{<br> template<typename T><br> T* begin(vec<T>& a)<br> {<br> return 0;<br> }<br><br> template<typename T><br> T* begin(const vec<T>& a)<br> {<br> return 0;<br> }<br><br> template<typename T><br> T* end(vec<T>& a)<br> {<br> return 0;<br> }<br><br> template<typename T><br> T* end(const vec<T>& a)<br> {<br> return 0;<br> }<br>}<br><br>using namespace std;<br><br>int main()<br>{<br> vec<char> vecDef;<br> for(auto it:vecDef);<br><br> return 0;<br>}<br><br></div><div>clang compile: clang++ -std=c++11 rangedfor.cpp (the code above)<br></div><div>result:rangedfor.cpp:37:14: error invalide range expression of type 'vec<char>'; no viable 'begin' function available<br></div><div><br></div>i already read <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__comments.gmane.org_gmane.comp.compilers.clang.devel_31712&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=ImzhkWDMFEMiWBqnwuyC-isY3Kc5XNTD5dRy8mg7X7M&s=un4RlsLD0nXrDD6ZtmK66JmSdLCsq7gnYrPB2kk46WM&e=" target="_blank">http://comments.gmane.org/gmane.comp.compilers.clang.devel/31712</a> but in that, he creates a new begin and her,e i create an overload and this is enabled:<br><br><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__en.cppreference.com_w_cpp_iterator_begin&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=ImzhkWDMFEMiWBqnwuyC-isY3Kc5XNTD5dRy8mg7X7M&s=v3nzN8N0CSO2-EMbtjLy1FyKt25ZrRkBTqK08lWZHY4&e=" target="_blank">http://en.cppreference.com/w/cpp/iterator/begin</a> see <span>User-defined overloads</span> part<br><br></div>The question is: am i intepret this wrong or this is a bug or what? the g++ , and visual c++ compile this code without a question.<br></div></div></blockquote><div><br></div><div>That's a bug in those other compilers. You're supposed to put the non-member begin/end functions in the same namespace as your container.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div>clang version: 26 May 2015 3.6.1<div><div><div>release windows, but in linux the same problem stands<br><br></div><div>Thanks János<br></div><div><br></div></div></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>