[cfe-commits] r102290 - in /cfe/trunk: lib/Sema/SemaInit.cpp lib/Sema/SemaOverload.cpp test/CodeGenCXX/temporaries.cpp

Douglas Gregor dgregor at apple.com
Sat Apr 24 17:55:24 PDT 2010


Author: dgregor
Date: Sat Apr 24 19:55:24 2010
New Revision: 102290

URL: http://llvm.org/viewvc/llvm-project?rev=102290&view=rev
Log:
When copying a temporary object to initialize an entity for which the
temporary needs to be bound, bind the copy object. Otherwise, we won't
end up calling the destructor for the copy. Fixes Boost.Optional.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/CodeGenCXX/temporaries.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=102290&r1=102289&r2=102290&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sat Apr 24 19:55:24 2010
@@ -3355,8 +3355,14 @@
                                 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,

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=102290&r1=102289&r2=102290&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sat Apr 24 19:55:24 2010
@@ -3703,7 +3703,7 @@
     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) {

Modified: cfe/trunk/test/CodeGenCXX/temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/temporaries.cpp?rev=102290&r1=102289&r2=102290&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/temporaries.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/temporaries.cpp Sat Apr 24 19:55:24 2010
@@ -301,3 +301,21 @@
     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);
+  }
+}





More information about the cfe-commits mailing list