Support for use of default argument in constructors.
work in progress. llvm-svn: 78132
This commit is contained in:
parent
7ce1fe2d04
commit
800f37262c
|
@ -511,6 +511,12 @@ public:
|
|||
|
||||
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) {
|
||||
|
|
|
@ -395,9 +395,13 @@ CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType 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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2360,8 +2360,29 @@ void Sema::InitializeVarWithConstructor(VarDecl *VD,
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue