forked from OSchip/llvm-project
Improved support for default arguments in constructors for class templates.
llvm-svn: 79984
This commit is contained in:
parent
5fed82025e
commit
10ebe78730
|
@ -2442,29 +2442,28 @@ Sema::BuildCXXConstructExpr(QualType DeclInitType,
|
||||||
bool Elidable,
|
bool Elidable,
|
||||||
Expr **Exprs,
|
Expr **Exprs,
|
||||||
unsigned NumExprs) {
|
unsigned NumExprs) {
|
||||||
CXXConstructExpr *Temp = CXXConstructExpr::Create(Context, DeclInitType,
|
ExprOwningPtr<CXXConstructExpr> Temp(this,
|
||||||
Constructor,
|
CXXConstructExpr::Create(Context,
|
||||||
Elidable, Exprs, NumExprs);
|
DeclInitType,
|
||||||
|
Constructor,
|
||||||
|
Elidable,
|
||||||
|
Exprs,
|
||||||
|
NumExprs));
|
||||||
// default arguments must be added to constructor call expression.
|
// default arguments must be added to constructor call expression.
|
||||||
FunctionDecl *FDecl = cast<FunctionDecl>(Constructor);
|
FunctionDecl *FDecl = cast<FunctionDecl>(Constructor);
|
||||||
unsigned NumArgsInProto = FDecl->param_size();
|
unsigned NumArgsInProto = FDecl->param_size();
|
||||||
for (unsigned j = NumExprs; j != NumArgsInProto; j++) {
|
for (unsigned j = NumExprs; j != NumArgsInProto; j++) {
|
||||||
Expr *DefaultExpr = FDecl->getParamDecl(j)->getDefaultArg();
|
ParmVarDecl *Param = FDecl->getParamDecl(j);
|
||||||
|
|
||||||
// If the default expression creates temporaries, we need to
|
OwningExprResult ArgExpr =
|
||||||
// push them to the current stack of expression temporaries so they'll
|
BuildCXXDefaultArgExpr(/*FIXME:*/SourceLocation(),
|
||||||
// be properly destroyed.
|
FDecl, Param);
|
||||||
if (CXXExprWithTemporaries *E
|
if (ArgExpr.isInvalid())
|
||||||
= dyn_cast_or_null<CXXExprWithTemporaries>(DefaultExpr)) {
|
return ExprError();
|
||||||
assert(!E->shouldDestroyTemporaries() &&
|
|
||||||
"Can't destroy temporaries in a default argument expr!");
|
Temp->setArg(j, ArgExpr.takeAs<Expr>());
|
||||||
for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I)
|
|
||||||
ExprTemporaries.push_back(E->getTemporary(I));
|
|
||||||
}
|
|
||||||
Expr *Arg = CXXDefaultArgExpr::Create(Context, FDecl->getParamDecl(j));
|
|
||||||
Temp->setArg(j, Arg);
|
|
||||||
}
|
}
|
||||||
return Owned(Temp);
|
return move(Temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sema::InitializeVarWithConstructor(VarDecl *VD,
|
bool Sema::InitializeVarWithConstructor(VarDecl *VD,
|
||||||
|
|
|
@ -18,3 +18,11 @@ void g() {
|
||||||
f3(10);
|
f3(10);
|
||||||
f3(S()); // expected-note{{in instantiation of default argument for 'f3<struct S>' required here}}
|
f3(S()); // expected-note{{in instantiation of default argument for 'f3<struct S>' required here}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T> struct F {
|
||||||
|
F(T t = 10);
|
||||||
|
};
|
||||||
|
|
||||||
|
void g2() {
|
||||||
|
F<int> f;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue