https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89548
Bug ID: 89548 Summary: reinterpret_cast treats xvalue as prvalue Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ndkrempel at gmail dot com Target Milestone: --- The following program fails to compile (with -std= any of c++11, c++14, c++17, c++2a): int main() { reinterpret_cast<int&&>(static_cast<int&&>(0)); } The error reported is: gcc-xvalue-bug.cc: In function ‘int main()’: gcc-xvalue-bug.cc:8:48: error: invalid cast of an rvalue expression of type ‘int’ to type ‘int&&’ reinterpret_cast<int&&>(static_cast<int&&>(0)); I.e. reinterpret_cast is treating its argument as a prvalue of type "int" rather than an xvalue of type "int&&". Testing indicates that the return value from the static_cast is of the correct type and value category, so the problem lies with the reinterpret_cast. The static_cast expression could also be replaced with a function returning "int&&" and the same problem occurs. The same problem also occurs when less trivial conversions are requested, for example "reinterpret_cast<unsigned int&&>(static_cast<int&&>(0))". For comparison, clang does not give an error, and that is consistent with my reading of the standards.