Upgraded Xcode today (and underlying clang went up to clang-1200.0.32.21
), and started getting ambiguous comparison errors like described here. But in that example the lack of const was evident, while for me the issue seems to be an inherited comparison operator. Here is a minimal example:
struct Bar
{
bool operator==(const Bar&) const
{
return true;
}
};
struct Foo : Bar
{
using Bar::operator==;
#if defined(USE_FOO)
bool operator==(const Foo&) const
{
return true;
}
#endif
};
int main()
{
Foo a,b;
if (a == b)
{
return 0;
}
else
{
return 1;
}
}
So, when compiling with clang++ -std=c++2a
it gives:
warning: ISO C++20 considers use of overloaded operator '=='
(with operand types 'Foo' and 'Foo') to be ambiguous despite there being a
unique best viable function [-Wambiguous-reversed-operator]
if (a == b)
~ ^ ~
test.cpp:3:10: note: ambiguity is between a regular call to this operator and a
call with the argument order reversed
bool operator==(const Bar&) const
^
while clang++ -std=c++2a -DUSE_FOO
works.
Is there a legitimate cause that breaks use of inherited operators or is this an Apple clang bug?