I have an old C++ project which I recently tried use after not compiling it for a while, only to find that g++ borked on it. The problem is reducible to this:
g++ now complains that "b - 1" is ambiguous, because the C++ standard says so even though the worst conversion for B::operator-(unsigned int) is better than the worst conversion for operator-(const A&, T). Is this true?
Code:
class A
{
public:
A() { }
template <typename T> A(T t) { }
};
template <typename T>
A
operator-(const A& lhs, T rhs)
{ return A(); }
class B
{
public:
B() { }
B operator-(unsigned int rhs) { return B(); }
};
int
main()
{
B b;
b - 1;
return 0;
}
Comment