If some struct A
has explicitly declared operator ==
method, but at the same time there is a global operator ==
accepting arguments of type A
, then equality comparison shall result in ambiguity error.
In C++20 we can call inequality operator !=
, which the compiler will interpret as the negation of equality operator. I though that in the same circumstances ambiguity error shall appear as well, and indeed GCC and Clang show it, but the latest Visual Studio 2019 accepts the code:
struct A {
bool operator ==(const A&) const = delete;
};
bool operator ==(const A&, const A&) { return true; }
int main() {
A a;
//a == a; //error everywhere
return a != a; //ok in MSVC
}
Demo: https://gcc.godbolt.org/z/ds53Wv783
Is it simply a bug in MSVC?
It appears to be a bug in MSVC, which is expected to be fixed soon: https://developercommunity.visualstudio.com/t/incorrect-acceptable-of-ambiguous-operator/1535876
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With