[cfe-commits] r72629 - in /cfe/trunk/lib/Sema: Sema.h SemaExprCXX.cpp
Anders Carlsson
andersca at mac.com
Sat May 30 13:36:53 PDT 2009
Author: andersca
Date: Sat May 30 15:36:53 2009
New Revision: 72629
URL: http://llvm.org/viewvc/llvm-project?rev=72629&view=rev
Log:
Add Sema::MaybeBindToTemporary which takes an expression and (if needed) wraps it in a CXXBindTemporaryExpr. Use this when creating CXXTemporaryObjectExprs.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprCXX.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=72629&r1=72628&r2=72629&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sat May 30 15:36:53 2009
@@ -1494,7 +1494,12 @@
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 {
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=72629&r1=72628&r2=72629&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat May 30 15:36:53 2009
@@ -207,10 +207,11 @@
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 @@
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!");
More information about the cfe-commits
mailing list