mercredi 18 novembre 2020

Why isn't clang throwing an error when casting an xvalue to a non-const lvalue reference?

Can someone explain why the clang doesn't throw an error on the first example in the following code while it does for the second example? Is it somehow related to the result of the static_cast being an xvalue?

int& example1 = reinterpret_cast<int&>(static_cast<int&&>(10));
//(gcc 10.2) error: invalid cast of an rvalue expression of type 'int' to type 'int&'
//(clang 11.0.0) no errors

int& example2 = reinterpret_cast<int&>(10);
//(gcc 10.2) error: invalid cast of an rvalue expression of type 'int' to type 'int&'
//(clang 11.0.0) error: reinterpret_cast from rvalue to reference type 'int &'

Aucun commentaire:

Enregistrer un commentaire