#include <compare>
struct A
{
int n;
auto operator <=>(const A&) const noexcept = default;
};
struct B
{
int n;
auto operator <=>(const B& rhs) const noexcept
{
return n <=> rhs.n;
}
};
int main()
{
A{} == A{}; // ok
B{} == B{}; // error: invalid operands to binary expression
}
用 clang-10 编译为clang -std=c++20 -stdlib=libc++ main.cpp
为什么A{} == A{}
有效但无效B{} == B{}
?