]> granicus.if.org Git - clang/commitdiff
Add Sema::MaybeBindToTemporary which takes an expression and (if needed) wraps it...
authorAnders Carlsson <andersca@mac.com>
Sat, 30 May 2009 20:36:53 +0000 (20:36 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 30 May 2009 20:36:53 +0000 (20:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72629 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaExprCXX.cpp

index 6214eb5a1116b4ee8db69540602decd3aa00497c..f630e1d6fbc54452c5855f876135ea55e5684d7d 100644 (file)
@@ -1494,7 +1494,12 @@ public:
                                     CXXConstructorDecl *Constructor,
                                     QualType DeclInitType, 
                                     Expr **Exprs, unsigned NumExprs);
-  
+
+  /// MaybeBindToTemporary - If the passed in expression has a record type with
+  /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
+  /// it simply returns the passed in expression.
+  OwningExprResult MaybeBindToTemporary(Expr *E);
+
   /// InitializationKind - Represents which kind of C++ initialization
   /// [dcl.init] a routine is to perform.
   enum InitializationKind {
index 923aa1d74279f4497baac6f0818f6e2bb0dc6cd3..b6ccb99d6ba0594cae57ff480557ee794cc50600 100644 (file)
@@ -207,10 +207,11 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
       ExprTemporaries.push_back(Temp);
       
       exprs.release();
-      return Owned(new (Context) CXXTemporaryObjectExpr(Context, Temp, 
-                                                        Constructor, Ty,
-                                                        TyBeginLoc,  Exprs,
-                                                        NumExprs, RParenLoc));
+      
+      Expr *E = new (Context) CXXTemporaryObjectExpr(Context, Temp, Constructor, 
+                                                     Ty, TyBeginLoc, Exprs,
+                                                     NumExprs, RParenLoc);
+      return MaybeBindToTemporary(E);
     }
 
     // Fall through to value-initialize an object of class type that
@@ -1529,6 +1530,22 @@ QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) {
   return QualType();
 }
 
+Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) {
+  const RecordType *RT = E->getType()->getAsRecordType();
+  if (!RT)
+    return Owned(E);
+  
+  CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
+  if (RD->hasTrivialDestructor())
+    return Owned(E);
+  
+  CXXTemporary *Temp = CXXTemporary::Create(Context, 
+                                            RD->getDestructor(Context));
+
+  // FIXME: Add the temporary to the temporaries vector.
+  return Owned(CXXBindTemporaryExpr::Create(Context, Temp, E));
+}
+
 Sema::OwningExprResult Sema::ActOnFinishFullExpr(ExprArg Arg) {
   Expr *FullExpr = Arg.takeAs<Expr>();
   assert(FullExpr && "Null full expr!");