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. llvm-svn: 155789
This commit is contained in:
parent
4f402bd985
commit
db05f1fb08
|
@ -1504,10 +1504,9 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr,
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,10 @@ template<typename T> T&& xvalue();
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue