summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-08-16 05:13:48 +0000
committerAnders Carlsson <andersca@mac.com>2009-08-16 05:13:48 +0000
commit250aada4b96c0dcc7bcf6085106871af1271f39d (patch)
treea3e4c1494bbd417732b1d5ec6c37a99d289ec305 /clang/lib
parent8a4c35dd185feb72c95e6593a7393c7061d4a6cb (diff)
downloadbcm5719-llvm-250aada4b96c0dcc7bcf6085106871af1271f39d.tar.gz
bcm5719-llvm-250aada4b96c0dcc7bcf6085106871af1271f39d.zip
AddInitializerToDecl can't take a FullExprArg. Make it take an ExprArg, and create the CXXExprWithTemporaries before setting the initializer on the VarDecl.
llvm-svn: 79176
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Frontend/PrintParserCallbacks.cpp2
-rw-r--r--clang/lib/Parse/ParseDecl.cpp2
-rw-r--r--clang/lib/Sema/Sema.h10
-rw-r--r--clang/lib/Sema/SemaDecl.cpp6
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp28
-rw-r--r--clang/lib/Sema/SemaExprCXX.cpp6
-rw-r--r--clang/lib/Sema/SemaInit.cpp5
7 files changed, 41 insertions, 18 deletions
diff --git a/clang/lib/Frontend/PrintParserCallbacks.cpp b/clang/lib/Frontend/PrintParserCallbacks.cpp
index 2101a85f411..9d6ea73eefb 100644
--- a/clang/lib/Frontend/PrintParserCallbacks.cpp
+++ b/clang/lib/Frontend/PrintParserCallbacks.cpp
@@ -109,7 +109,7 @@ namespace {
/// This allows ActOnDeclarator to register "xx" prior to parsing the
/// initializer. The declaration above should still result in a warning,
/// since the reference to "xx" is uninitialized.
- virtual void AddInitializerToDecl(DeclPtrTy Dcl, FullExprArg Init) {
+ virtual void AddInitializerToDecl(DeclPtrTy Dcl, ExprArg Init) {
Out << __FUNCTION__ << "\n";
}
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 029d9b5aaec..9958bdf5668 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -446,7 +446,7 @@ Parser::DeclPtrTy Parser::ParseDeclarationAfterDeclarator(Declarator &D,
SkipUntil(tok::semi, true, true);
return DeclPtrTy();
}
- Actions.AddInitializerToDecl(ThisDecl, Actions.FullExpr(Init));
+ Actions.AddInitializerToDecl(ThisDecl, move(Init));
}
} else if (Tok.is(tok::l_paren)) {
// Parse C++ direct initializer: '(' expression-list ')'
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index d17e2f14989..d3bdec8f39e 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -503,7 +503,7 @@ public:
// argument locations.
llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs;
- virtual void AddInitializerToDecl(DeclPtrTy dcl, FullExprArg init);
+ virtual void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init);
void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit);
void ActOnUninitializedDecl(DeclPtrTy dcl, bool TypeContainsUndeducedAuto);
virtual void SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc);
@@ -1689,15 +1689,17 @@ public:
CXXConstructorDecl *Constructor,
QualType DeclInitType,
Expr **Exprs, unsigned NumExprs);
-
+
+ Expr *BuildCXXConstructExpr(QualType DeclInitType,
+ CXXConstructorDecl *Constructor,
+ Expr **Exprs, unsigned NumExprs);
+
/// BuildCXXConstructExpr - Creates a complete call to a constructor,
/// including handling of its default argument expressions.
Expr *BuildCXXConstructExpr(QualType DeclInitType,
CXXConstructorDecl *Constructor,
bool Elidable,
Expr **Exprs, unsigned NumExprs);
-
- Expr *BuildCXXCopyConstructExpr(Expr *Expr);
/// FinalizeVarWithDestructor - Prepare for calling destructor on the
/// constructed variable.
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index bf1dd91f74b..b672d0501a0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2996,8 +2996,8 @@ bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
return true;
}
-void Sema::AddInitializerToDecl(DeclPtrTy dcl, FullExprArg init) {
- AddInitializerToDecl(dcl, init.release(), /*DirectInit=*/false);
+void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init) {
+ AddInitializerToDecl(dcl, move(init), /*DirectInit=*/false);
}
/// AddInitializerToDecl - Adds the initializer Init to the
@@ -3160,6 +3160,8 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) {
Init->setType(DclT);
}
+ Init = MaybeCreateCXXExprWithTemporaries(Init,
+ /*ShouldDestroyTemporaries=*/true);
// Attach the initializer to the decl.
VDecl->setInit(Context, Init);
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index d460950824e..068978cd926 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2377,6 +2377,32 @@ void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
CopyConstructor->setUsed();
}
+Expr *Sema::BuildCXXConstructExpr(QualType DeclInitType,
+ CXXConstructorDecl *Constructor,
+ Expr **Exprs, unsigned NumExprs) {
+ bool Elidable = false;
+
+ // [class.copy]p15:
+ // Whenever a temporary class object is copied using a copy constructor, and
+ // this object and the copy have the same cv-unqualified type, an
+ // implementation is permitted to treat the original and the copy as two
+ // different ways of referring to the same object and not perform a copy at
+ //all, even if the class copy constructor or destructor have side effects.
+
+ // FIXME: Is this enough?
+ if (Constructor->isCopyConstructor(Context) && NumExprs == 1) {
+ Expr *E = Exprs[0];
+ while (CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E))
+ E = BE->getSubExpr();
+
+ if (isa<CallExpr>(E) || isa<CXXTemporaryObjectExpr>(E))
+ Elidable = true;
+ }
+
+ return BuildCXXConstructExpr(DeclInitType, Constructor, Elidable,
+ Exprs, NumExprs);
+}
+
/// BuildCXXConstructExpr - Creates a complete call to a constructor,
/// including handling of its default argument expressions.
Expr *Sema::BuildCXXConstructExpr(QualType DeclInitType,
@@ -2413,7 +2439,7 @@ void Sema::InitializeVarWithConstructor(VarDecl *VD,
QualType DeclInitType,
Expr **Exprs, unsigned NumExprs) {
Expr *Temp = BuildCXXConstructExpr(DeclInitType, Constructor,
- false, Exprs, NumExprs);
+ Exprs, NumExprs);
MarkDeclarationReferenced(VD->getLocation(), Constructor);
Temp = MaybeCreateCXXExprWithTemporaries(Temp, /*DestroyTemps=*/true);
VD->setInit(Context, Temp);
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 274893b99e9..f313c5653e8 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -902,11 +902,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
// FIXME: When can ToType be a reference type?
assert(!ToType->isReferenceType());
- // FIXME: Keep track of whether the copy constructor is elidable or not.
- bool Elidable = (isa<CallExpr>(From) ||
- isa<CXXTemporaryObjectExpr>(From));
- From = BuildCXXConstructExpr(ToType, SCS.CopyConstructor,
- Elidable, &From, 1);
+ From = BuildCXXConstructExpr(ToType, SCS.CopyConstructor, &From, 1);
return false;
}
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index f734d9347ac..ce6a99acd9d 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -176,10 +176,7 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
DirectInit? IK_Direct : IK_Copy);
if (!Constructor)
return true;
- bool Elidable = (isa<CallExpr>(Init) ||
- isa<CXXTemporaryObjectExpr>(Init));
- Init = BuildCXXConstructExpr(DeclType, Constructor, Elidable, &Init, 1);
- Init = MaybeCreateCXXExprWithTemporaries(Init, /*DestroyTemps=*/true);
+ Init = BuildCXXConstructExpr(DeclType, Constructor, &Init, 1);
return false;
}
OpenPOWER on IntegriCloud