In case of multiple inheritance if all parent classes have their own equality comparison operator ==, and the child class has a (friend) function operator ==, as in the example:
struct A {
bool operator ==(const A&) const = default;
};
struct B {
bool operator ==(const B&) const = default;
};
struct C : A, B {};
constexpr bool operator ==(const C&, const C&) { return true; }
static_assert( C{} == C{} );
GCC prints the following error about ambiguity in an attempt to compare child objects:
error: request for member 'operator==' is ambiguous
13 | static_assert( C{} == C{} );
note: candidates are: 'bool B::operator==(const B&) const'
note: 'bool A::operator==(const A&) const'
Demo: https://gcc.godbolt.org/z/W3qer376d
This error looks surprising, since operator ==(const C&, const C&) shall be preferred as the most suitable to the actual arguments. Is it simply a defect in GCC?