From 21e1c4ea0a96bcecfe5976304d84779949058648 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sun, 6 Sep 2009 16:54:02 +0000 Subject: [PATCH] Reapply 81096, now with a fix. Spot the bug: for (unsigned i = numargs; i < NumArgs; ++i) Args[0] = 0; ;) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81123 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprCXX.cpp | 2 ++ lib/Sema/SemaDeclCXX.cpp | 4 ++-- test/SemaTemplate/default-expr-arguments.cpp | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 0ffb152872..c532b8c590 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -403,6 +403,8 @@ CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, Args = new (C) Stmt*[NumArgs]; for (unsigned i = 0; i < numargs; ++i) Args[i] = args[i]; + for (unsigned i = numargs; i < NumArgs; ++i) + Args[i] = 0; } } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 3ee40e842c..89acfd14d6 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2899,8 +2899,8 @@ bool Sema::InitializeVarWithConstructor(VarDecl *VD, QualType DeclInitType, Expr **Exprs, unsigned NumExprs) { OwningExprResult TempResult = - BuildCXXConstructExpr(/*FIXME: ConstructLoc*/ SourceLocation(), - DeclInitType, Constructor, Exprs, NumExprs); + BuildCXXConstructExpr(VD->getLocation(), DeclInitType, Constructor, + Exprs, NumExprs); if (TempResult.isInvalid()) return true; diff --git a/test/SemaTemplate/default-expr-arguments.cpp b/test/SemaTemplate/default-expr-arguments.cpp index 925d52fb19..d689cc86e6 100644 --- a/test/SemaTemplate/default-expr-arguments.cpp +++ b/test/SemaTemplate/default-expr-arguments.cpp @@ -20,7 +20,7 @@ void g() { } template struct F { - F(T t = 10); + F(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}} void f(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}} }; @@ -34,6 +34,9 @@ void g2() { void g3(F f, F s) { f.f(); s.f(); // expected-note{{in instantiation of default function argument expression for 'f' required here}} + + F f2; + F s2; // expected-note{{in instantiation of default function argument expression for 'F' required here}} } template struct G { -- 2.40.0