The following code is treated differently by the compilers:
#include <compare>
struct A;
struct I {
virtual std::strong_ordering operator <=>(const A&) const {
return std::strong_ordering::equal;
}
};
struct A : I {
virtual std::strong_ordering operator <=>(const A&) const = default;
};
Both GCC and MSVC accept it, but not Clang which returns the error:
warning: explicitly defaulted three-way comparison operator is implicitly deleted [-Wdefaulted-function-deleted]
virtual std::strong_ordering operator <=>(const A&) const = default;
defaulted 'operator<=>' is implicitly deleted because there is no viable three-way comparison function for base class 'I'
error: deleted function 'operator<=>' cannot override a non-deleted function
virtual std::strong_ordering operator <=>(const A&) const = default;
Demo: https://gcc.godbolt.org/z/WGrGTe89z
It seems that Clang is the only one right here, since I::operator <=>(const I&) const is not defined, so A::operator <=>(const A&) const must be implicitly deleted, and a deleted method cannot override a not deleted method from I. Are the other compilers also within their rights to accept the code?