diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index f4b5a57ed532..c30b974af9d9 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2442,29 +2442,28 @@ Sema::BuildCXXConstructExpr(QualType DeclInitType, bool Elidable, Expr **Exprs, unsigned NumExprs) { - CXXConstructExpr *Temp = CXXConstructExpr::Create(Context, DeclInitType, - Constructor, - Elidable, Exprs, NumExprs); + ExprOwningPtr Temp(this, + CXXConstructExpr::Create(Context, + DeclInitType, + Constructor, + Elidable, + Exprs, + NumExprs)); // default arguments must be added to constructor call expression. FunctionDecl *FDecl = cast(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(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 = CXXDefaultArgExpr::Create(Context, FDecl->getParamDecl(j)); - Temp->setArg(j, Arg); + ParmVarDecl *Param = FDecl->getParamDecl(j); + + OwningExprResult ArgExpr = + BuildCXXDefaultArgExpr(/*FIXME:*/SourceLocation(), + FDecl, Param); + if (ArgExpr.isInvalid()) + return ExprError(); + + Temp->setArg(j, ArgExpr.takeAs()); } - return Owned(Temp); + return move(Temp); } bool Sema::InitializeVarWithConstructor(VarDecl *VD, diff --git a/clang/test/SemaTemplate/default-expr-arguments.cpp b/clang/test/SemaTemplate/default-expr-arguments.cpp index 87532effb58a..34d2d9d6fea5 100644 --- a/clang/test/SemaTemplate/default-expr-arguments.cpp +++ b/clang/test/SemaTemplate/default-expr-arguments.cpp @@ -18,3 +18,11 @@ void g() { f3(10); f3(S()); // expected-note{{in instantiation of default argument for 'f3' required here}} } + +template struct F { + F(T t = 10); +}; + +void g2() { + F f; +}