三路运算符<=>返回带有隐式转换函数的结构体

考虑以下无用的代码:

struct S{
  constexpr operator int() const { return 0; }
  constexpr auto operator<=>(S) const { return *this; }
};

static_assert(S{} <= S{});

Clang 和 MSVC 接受此代码,但 GCC拒绝它并显示错误消息:

error: no match for 'operator<=' (operand types are 'S' and 'int')

哪个编译器是对的?是怎么operator<=合成的operator<=>

以上是三路运算符&lt;=&gt;返回带有隐式转换函数的结构体的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>