reinterpret_cast 从右值到右值引用

reinterpret_cast from rvalue to rvalue reference

简单的编译测试一下。 gcc 接受以下内容,而 clang 和 msvc 拒绝它:https://godbolt.org/z/DlUasL

float test()
{
    return reinterpret_cast<float&&>(0x7F800000);
}

按照标准,哪一个是正确的?

reinterpret_cast 表达式试图执行的转换不在转换列表 [expr.reinterpret.cast] that a reinterpret_cast can perform [expr.reinterpret.cast]/1. 0x7F800000 is a literal of integral type. The only conversion reinterpret_cast could perform that converts from a value of integral type to some other type is that of turning such a value into a pointer type [expr.reinterpret.cast]/5. float&& is a reference type, not a pointer type. The only conversion reinterpret_cast can perform that converts to a reference type is that of converting a glvalue expression [expr.reinterpret.cast]/11 中。 0x7F800000 不是左值。因此,此代码为 ill-formed。 GCC 会接受这个事实让我感到非常惊讶,我想说,这绝对是一个应该报告的错误......