Just a simple does it compile test. gcc accepts the following while clang and msvc reject it: https://godbolt.org/z/DlUasL
float test()
{
return reinterpret_cast<float&&>(0x7F800000);
}
Which one is right according to the standard?
The conversion this reinterpret_cast
expression seeks to perform is not among the list of conversions [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
is not a glvalue. Thus, this code is ill-formed. The fact that GCC would accept this is quite surprising to me and, I would say, definitely a bug that should be reported…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With