diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 54683e127ec1..a67d1dec59e4 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -1504,10 +1504,9 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, } if (const ReferenceType *DestTypeTmp = DestType->getAs()) { - bool LValue = DestTypeTmp->isLValueReferenceType(); - if (LValue && !SrcExpr.get()->isLValue()) { - // Cannot cast non-lvalue to lvalue reference type. See the similar - // comment in const_cast. + if (!SrcExpr.get()->isGLValue()) { + // Cannot cast non-glvalue to (lvalue or rvalue) reference type. See the + // similar comment in const_cast. msg = diag::err_bad_cxx_cast_rvalue; return TC_NotApplicable; } diff --git a/clang/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp b/clang/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp index 22892a63ab16..212adc8c2bd4 100644 --- a/clang/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp +++ b/clang/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp @@ -10,7 +10,10 @@ template T&& xvalue(); void test_classification(char *ptr) { int (&fr0)(int) = reinterpret_cast(f); int &&ir0 = reinterpret_cast(*ptr); - int &&ir1 = reinterpret_cast(0); - int &&ir2 = reinterpret_cast('a'); + int &&ir1 = reinterpret_cast(0); // expected-error {{rvalue to reference type}} + int &&ir2 = reinterpret_cast('a'); // expected-error {{rvalue to reference type}} int &&ir3 = reinterpret_cast(xvalue()); + // Per DR1268, reinterpret_cast can convert between lvalues and xvalues. + int &ir4 = reinterpret_cast(xvalue()); + int &&ir5 = reinterpret_cast(*ptr); }