我<=>在C ++ 20中使用新的宇宙飞船运算符遇到一种奇怪的行为。我正在将Visual Studio 2019编译器与一起使用/std:c++latest。
这段代码可以正常编译:
#include <compare>
struct X
{
    int Dummy = 0;
    auto operator<=>(const X&) const = default; // Default implementation
};
int main()
{
    X a, b;
    a == b; // OK!
    return 0;
}但是,如果我将X更改为:
struct X
{
    int Dummy = 0;
    auto operator<=>(const X& other) const
    {
        return Dummy <=> other.Dummy;
    }
};我收到以下编译器错误:
error C2676: binary '==': 'X' does not define this operator or a conversion to a type acceptable to the predefined operator
我也在clang上尝试了这一点,并且得到了类似的行为。
我将对为什么默认实现operator==正确生成但自定义代码无法正确生成的一些解释表示赞赏。