From: Richard Smith Date: Tue, 15 May 2012 05:04:02 +0000 (+0000) Subject: PR12826: Converting an lvalue to an xvalue is a no-op conversion, not an lvalue-to... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dbbecccb8431bb4545fc01c6401abc4253667360;p=clang PR12826: Converting an lvalue to an xvalue is a no-op conversion, not an lvalue-to-rvalue conversion. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156803 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 2e1cc7c600..2ea07efde8 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -2033,8 +2033,7 @@ Sema::PerformMoveOrCopyInitialization(const InitializedEntity &Entity, if (AllowNRVO && (NRVOCandidate || getCopyElisionCandidate(ResultType, Value, true))) { ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, - Value->getType(), CK_LValueToRValue, - Value, VK_XValue); + Value->getType(), CK_NoOp, Value, VK_XValue); Expr *InitExpr = &AsRvalue; InitializationKind Kind @@ -2069,8 +2068,7 @@ Sema::PerformMoveOrCopyInitialization(const InitializedEntity &Entity, // Promote "AsRvalue" to the heap, since we now need this // expression node to persist. Value = ImplicitCastExpr::Create(Context, Value->getType(), - CK_LValueToRValue, Value, 0, - VK_XValue); + CK_NoOp, Value, 0, VK_XValue); // Complete type-checking the initialization of the return type // using the constructor we found. diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index a9e1008ec6..263e8411b4 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -1258,3 +1258,11 @@ namespace InvalidClasses { auto& b = y.b; } } + +// Indirectly test that an implicit lvalue to xvalue conversion performed for +// an NRVO move operation isn't implemented as CK_LValueToRValue. +namespace PR12826 { + struct Foo {}; + constexpr Foo id(Foo x) { return x; } + constexpr Foo res(id(Foo())); +}