[cfe-dev] Range for loop and custom container
János Hack
hjjohny at gmail.com
Thu Jun 4 13:09:34 PDT 2015
Hi all,
Please consider this example:
template<typename T>
struct vec{};
namespace std
{
template<typename T>
T* begin(vec<T>& a)
{
return 0;
}
template<typename T>
T* begin(const vec<T>& a)
{
return 0;
}
template<typename T>
T* end(vec<T>& a)
{
return 0;
}
template<typename T>
T* end(const vec<T>& a)
{
return 0;
}
}
using namespace std;
int main()
{
vec<char> vecDef;
for(auto it:vecDef);
return 0;
}
clang compile: clang++ -std=c++11 rangedfor.cpp (the code above)
result:rangedfor.cpp:37:14: error invalide range expression of type
'vec<char>'; no viable 'begin' function available
i already read
http://comments.gmane.org/gmane.comp.compilers.clang.devel/31712 but in
that, he creates a new begin and her,e i create an overload and this is
enabled:
http://en.cppreference.com/w/cpp/iterator/begin see User-defined overloads
part
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.
clang version: 26 May 2015 3.6.1
release windows, but in linux the same problem stands
Thanks János
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150604/c984bb29/attachment.html>
More information about the cfe-dev
mailing list