[cfe-commits] r155789 - in /cfe/trunk: lib/Sema/SemaCast.cpp test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Sun Apr 29 01:24:44 PDT 2012
Author: rsmith
Date: Sun Apr 29 03:24:44 2012
New Revision: 155789
URL: http://llvm.org/viewvc/llvm-project?rev=155789&view=rev
Log:
PR9546, DR1268: A prvalue cannot be reinterpret_cast to an rvalue reference
type. But a glvalue can be reinterpret_cast to either flavor of reference.
Modified:
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp
Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=155789&r1=155788&r2=155789&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Sun Apr 29 03:24:44 2012
@@ -1504,10 +1504,9 @@
}
if (const ReferenceType *DestTypeTmp = DestType->getAs<ReferenceType>()) {
- 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;
}
Modified: cfe/trunk/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp?rev=155789&r1=155788&r2=155789&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp Sun Apr 29 03:24:44 2012
@@ -10,7 +10,10 @@
void test_classification(char *ptr) {
int (&fr0)(int) = reinterpret_cast<int (&&)(int)>(f);
int &&ir0 = reinterpret_cast<int &&>(*ptr);
- int &&ir1 = reinterpret_cast<int &&>(0);
- int &&ir2 = reinterpret_cast<int &&>('a');
+ int &&ir1 = reinterpret_cast<int &&>(0); // expected-error {{rvalue to reference type}}
+ int &&ir2 = reinterpret_cast<int &&>('a'); // expected-error {{rvalue to reference type}}
int &&ir3 = reinterpret_cast<int &&>(xvalue<char>());
+ // Per DR1268, reinterpret_cast can convert between lvalues and xvalues.
+ int &ir4 = reinterpret_cast<int &>(xvalue<char>());
+ int &&ir5 = reinterpret_cast<int &&>(*ptr);
}
More information about the cfe-commits
mailing list