Using Visual Studio 2010 SP1:
#include <vector> //namespace XXX { struct Test { bool operator==(const Test& r) const { return true; } }; //} //typedef XXX::Test Test; template <typename T> inline bool operator!=(const T& l,const T& r) { return !(l==r); } int main() { std::vector<Test> vt; std::vector<Test> vt2 = std::move(vt); return 0; }
If I compile the code above as is, it fails with this error:
1>C:\apps\MVS10\VC\include\vector(609): error C2593: 'operator !=' is ambiguous 1> C:\apps\MVS10\VC\include\xmemory(268): could be 'bool std::operator !=<_Ty,_Ty>(const std::allocator<_Ty> &,const std::allocator<_Ty> &) throw()' 1> with 1> [ 1> _Ty=Test 1> ] 1> test.cpp(11): or 'bool operator !=<std::allocator<_Ty>>(const T &,const T &)' [found using argument-dependent lookup] 1> with 1> [ 1> _Ty=Test, 1> T=std::allocator<Test> 1> ] 1> while trying to match the argument list '(std::allocator<_Ty>, std::allocator<_Ty>)' 1> with 1> [ 1> _Ty=Test 1> ] 1> C:\apps\MVS10\VC\include\vector(606) : while compiling class template member function 'void std::vector<_Ty>::_Assign_rv(std::vector<_Ty> &&)' 1> with 1> [ 1> _Ty=Test 1> ]
... where vector(609)
resolves this line:
else if (get_allocator() != _Right.get_allocator())
OTOH, if I uncomment the lines associated with namespace XXX
, it compiles without complaint.
I should think this is a compiler error, but I'm looking for some independent verification.
EDIT: Just as an explanation, I came across this situation when I first recompiled the old code with VS2010. Global operator a few years ago (now removed). I just could not understand why some code failed and others did not. The code above is my distillation of a failed event (obviously, the old code will not contain calls to std::move()
).
UPDATE: I registered a bug with MS and they replied that it was fixed "in the next version of the compiler" - I suppose it means Visual C ++ 11. See: http://connect.microsoft.com/VisualStudio/ feedback / details / 731692 / regression-involving-global-operator-and-std-vector