[cfe-users] Templated operator overloading in C++11 mode
Matthias Maier
tamiko+LLVM at kyomu.43-1.org
Mon Oct 14 12:51:03 PDT 2013
Hi folks,
I've a question about Clang's behaviour with the following snippet of
code:
#include<iostream>
#include<vector>
class Foo
{
public:
template<typename T>
Foo& operator<< (const T &t)
{
std::cout << 'a' << std::endl;
return *this;
}
};
template<typename T>
Foo& operator<< (Foo &foo, const std::vector<T> &t)
{
std::cout << 'b' << std::endl;
return foo;
};
int main()
{
Foo foo;
std::vector<int> bar;
foo << bar;
}
Compiling and running it _without_ -std=c++11 gives 'b', compiling
_with_ -std=c++11 leads to 'a', the second templated operator
is ignored. gcc and icc still give 'b' in c++11 mode.
So, what is the correct behaviour?
Best,
Matthias
More information about the cfe-users
mailing list