]> granicus.if.org Git - clang/commitdiff
When copying a temporary object to initialize an entity for which the
authorDouglas Gregor <dgregor@apple.com>
Sun, 25 Apr 2010 00:55:24 +0000 (00:55 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 25 Apr 2010 00:55:24 +0000 (00:55 +0000)
temporary needs to be bound, bind the copy object. Otherwise, we won't
end up calling the destructor for the copy. Fixes Boost.Optional.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102290 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
lib/Sema/SemaOverload.cpp
test/CodeGenCXX/temporaries.cpp

index e1269a7e12975aae15f213e48dd36cea915e1cb1..c413e67f042ce2be471deec7772c86ea8b48923c 100644 (file)
@@ -3355,8 +3355,14 @@ static Sema::OwningExprResult CopyObject(Sema &S,
                                 Loc, ConstructorArgs))
     return S.ExprError();
 
-  return S.BuildCXXConstructExpr(Loc, T, Constructor, Elidable,
-                                 move_arg(ConstructorArgs));
+  // Actually perform the constructor call.
+  CurInit = S.BuildCXXConstructExpr(Loc, T, Constructor, Elidable,
+                                    move_arg(ConstructorArgs));
+  
+  // If we're supposed to bind temporaries, do so.
+  if (!CurInit.isInvalid() && shouldBindAsTemporary(Entity))
+    CurInit = S.MaybeBindToTemporary(CurInit.takeAs<Expr>());
+  return move(CurInit);
 }
 
 void InitializationSequence::PrintInitLocationNote(Sema &S,
index 463f1899ed9bc7b07f87a0ee26bf60a23fffa2bd..06b5fcb318c39ea0b35498f6b8c5fea6b4d78bc3 100644 (file)
@@ -3703,7 +3703,7 @@ static  Qualifiers CollectVRQualifiers(ASTContext &Context, Expr* ArgExpr) {
     const RecordType *TyRec;
     if (const MemberPointerType *RHSMPType =
         ArgExpr->getType()->getAs<MemberPointerType>())
-      TyRec = cast<RecordType>(RHSMPType->getClass());
+      TyRec = RHSMPType->getClass()->getAs<RecordType>();
     else
       TyRec = ArgExpr->getType()->getAs<RecordType>();
     if (!TyRec) {
index 4aad3c0056ca05b21178a7a02f7769b770076d7a..f9a9ed100ab5b0253f436cabcdbfbf2e67edee54 100644 (file)
@@ -301,3 +301,21 @@ namespace PR6648 {
     zed(foo);
   }
 }
+
+namespace UserConvertToValue {
+  struct X {
+    X(int);
+    X(const X&);
+    ~X();
+  };
+
+  void f(X);
+
+  // CHECK: void @_ZN18UserConvertToValue1gEv() 
+  void g() {
+    // CHECK: call void @_ZN18UserConvertToValue1XC1Ei
+    // CHECK: call void @_ZN18UserConvertToValue1fENS_1XE
+    // CHECK: call void @_ZN18UserConvertToValue1XD1Ev
+    f(1);
+  }
+}