As far as I understand C++ ADL this compilation error is legit. But at the same time I dont understand why this failure happens only on clang + libc++ configuration, and only when we use reverse iterators. Normal vector iterators dont lead to this.
#include <vector>
#include <iostream>
namespace NS1
{
struct Foo
{
explicit Foo(const int i): m_i(i)
{}
bool operator==(const Foo& that) const
{
return this->m_i == that.m_i;
}
int m_i;
};
template <typename T>
bool operator!=(const T& a, const T& b)
{
return !(a == b);
}
}
int main(void)
{
std::vector<NS1::Foo> n;
// error: use of overloaded operator '!=' is ambiguous (with operand types 'std::__1::reverse_iterator
for(auto it = n.rbegin(); it != n.rend(); ++it)
{
std::cout<<it->m_i;
}
}
The error is:
error: use of overloaded operator '!=' is ambiguous (with operand types 'std::__1::reverse_iterator<std::__1::__wrap_iter<NS1::Foo *>>' and 'std::__1::vector<NS1::Foo, std::__1::allocator<NS1::Foo>>::reverse_iterator' (aka 'reverse_iterator<__wrap_iter<NS1::Foo *>>'))
for(auto it = n.rbegin(); it != n.rend(); ++it)
~~ ^ ~~~~~~~~
Does anyone know if it is possible to make clang + libc++ configuration behave like the rest of configurations (gcc, msvc)?
Here is a small example on godbolt: https://godbolt.org/z/8cKPY6