Support for use of default argument in constructors.
work in progress.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78132 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index a550e66..76bd71c 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -2360,8 +2360,29 @@
CXXConstructorDecl *Constructor,
QualType DeclInitType,
Expr **Exprs, unsigned NumExprs) {
- Expr *Temp = CXXConstructExpr::Create(Context, DeclInitType, Constructor,
- false, Exprs, NumExprs);
+ CXXConstructExpr *Temp = CXXConstructExpr::Create(Context, DeclInitType,
+ Constructor,
+ false, Exprs, NumExprs);
+ // default arguments must be added to constructor call expression.
+ FunctionDecl *FDecl = cast<FunctionDecl>(Constructor);
+ unsigned NumArgsInProto = FDecl->param_size();
+ for (unsigned j = NumExprs; j != NumArgsInProto; j++) {
+ Expr *DefaultExpr = FDecl->getParamDecl(j)->getDefaultArg();
+
+ // If the default expression creates temporaries, we need to
+ // push them to the current stack of expression temporaries so they'll
+ // be properly destroyed.
+ if (CXXExprWithTemporaries *E
+ = dyn_cast_or_null<CXXExprWithTemporaries>(DefaultExpr)) {
+ assert(!E->shouldDestroyTemporaries() &&
+ "Can't destroy temporaries in a default argument expr!");
+ for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I)
+ ExprTemporaries.push_back(E->getTemporary(I));
+ }
+ Expr *Arg = new (Context) CXXDefaultArgExpr(FDecl->getParamDecl(j));
+ Temp->setArg(j, Arg);
+ }
+
MarkDeclarationReferenced(VD->getLocation(), Constructor);
VD->setInit(Context, Temp);
}