diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/ExprCXX.cpp | 13 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 21 |
2 files changed, 31 insertions, 3 deletions
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 5444a7748c..e4538fdfed 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -352,6 +352,19 @@ const char *CXXNamedCastExpr::getCastName() const { } } +CXXDefaultArgExpr * +CXXDefaultArgExpr::Create(ASTContext &C, ParmVarDecl *Param, Expr *SubExpr) { + void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *)); + return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Param, SubExpr); +} + +void CXXDefaultArgExpr::DoDestroy(ASTContext &C) { + if (Param.getInt()) + getExpr()->Destroy(C); + this->~CXXDefaultArgExpr(); + C.Deallocate(this); +} + CXXTemporary *CXXTemporary::Create(ASTContext &C, const CXXDestructorDecl *Destructor) { return new (C) CXXTemporary(Destructor); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 09e1d6f455..c56eeefffd 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3078,15 +3078,30 @@ Sema::OwningExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc, if (Result.isInvalid()) return ExprError(); - if (SetParamDefaultArgument(Param, move(Result), - /*FIXME:EqualLoc*/ - UninstExpr->getSourceRange().getBegin())) + // Check the expression as an initializer for the parameter. + InitializedEntity Entity + = InitializedEntity::InitializeParameter(Param); + InitializationKind Kind + = InitializationKind::CreateCopy(Param->getLocation(), + /*FIXME:EqualLoc*/UninstExpr->getSourceRange().getBegin()); + Expr *ResultE = Result.takeAs<Expr>(); + + InitializationSequence InitSeq(*this, Entity, Kind, &ResultE, 1); + Result = InitSeq.Perform(*this, Entity, Kind, + MultiExprArg(*this, (void**)&ResultE, 1)); + if (Result.isInvalid()) return ExprError(); + + // Build the default argument expression. + return Owned(CXXDefaultArgExpr::Create(Context, Param, + Result.takeAs<Expr>())); } // If the default expression creates temporaries, we need to // push them to the current stack of expression temporaries so they'll // be properly destroyed. + // FIXME: We should really be rebuilding the default argument with new + // bound temporaries; see the comment in PR5810. for (unsigned i = 0, e = Param->getNumDefaultArgTemporaries(); i != e; ++i) ExprTemporaries.push_back(Param->getDefaultArgTemporary(i)); } |