PR12826: Converting an lvalue to an xvalue is a no-op conversion, not an lvalue-to...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 May 2012 05:04:02 +0000 (05:04 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 May 2012 05:04:02 +0000 (05:04 +0000)
llvm-svn: 156803

clang/lib/Sema/SemaStmt.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp

index 2e1cc7c..2ea07ef 100644 (file)
@@ -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.
index a9e1008..263e841 100644 (file)
@@ -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()));
+}