unsigned getNumArgs() const { return NumArgs; }
+ /// setArg - Set the specified argument.
+ void setArg(unsigned Arg, Expr *ArgExpr) {
+ assert(Arg < NumArgs && "Arg access out of range!");
+ Args[Arg] = ArgExpr;
+ }
+
virtual SourceRange getSourceRange() const { return SourceRange(); }
static bool classof(const Stmt *T) {
(T->isDependentType() ||
CallExpr::hasAnyValueDependentArguments(args, numargs))),
Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) {
+ // leave room for default arguments;
+ FunctionDecl *FDecl = cast<FunctionDecl>(D);
+ unsigned NumArgsInProto = FDecl->param_size();
+ NumArgs += (NumArgsInProto - numargs);
if (NumArgs > 0) {
Args = new (C) Stmt*[NumArgs];
- for (unsigned i = 0; i < NumArgs; ++i)
+ for (unsigned i = 0; i < numargs; ++i)
Args[i] = args[i];
}
}
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);
}