From 1bc688dc6029ffc6975378d95f6f6d95051b1c11 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 9 Nov 2009 19:27:57 +0000 Subject: [PATCH] Make sure that we instantiate default function arguments for an overloaded operator(). llvm-svn: 86581 --- clang/lib/Sema/SemaOverload.cpp | 9 ++++++++- .../SemaTemplate/default-expr-arguments.cpp | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 00a55b9c3653..f57ce140e520 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -5420,7 +5420,14 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, QualType ProtoArgType = Proto->getArgType(i); IsError |= PerformCopyInitialization(Arg, ProtoArgType, "passing"); } else { - Arg = CXXDefaultArgExpr::Create(Context, Method->getParamDecl(i)); + OwningExprResult DefArg + = BuildCXXDefaultArgExpr(LParenLoc, Method, Method->getParamDecl(i)); + if (DefArg.isInvalid()) { + IsError = true; + break; + } + + Arg = DefArg.takeAs(); } TheCall->setArg(i + 1, Arg); diff --git a/clang/test/SemaTemplate/default-expr-arguments.cpp b/clang/test/SemaTemplate/default-expr-arguments.cpp index c136eee0f62b..34ac2d967efc 100644 --- a/clang/test/SemaTemplate/default-expr-arguments.cpp +++ b/clang/test/SemaTemplate/default-expr-arguments.cpp @@ -65,8 +65,8 @@ void test_x0(X0 xi) { xi.f(17); } -struct NotDefaultConstructible { // expected-note{{candidate}} - NotDefaultConstructible(int); // expected-note{{candidate}} +struct NotDefaultConstructible { // expected-note 2{{candidate}} + NotDefaultConstructible(int); // expected-note 2{{candidate}} }; void test_x0_not_default_constructible(X0 xn) { @@ -85,6 +85,18 @@ void test_X1() { X1 x1; } +template +struct X2 { + void operator()(T = T()); // expected-error{{no matching}} +}; + +void test_x2(X2 x2i, X2 x2n) { + x2i(); + x2i(17); + x2n(NotDefaultConstructible(17)); + x2n(); // expected-note{{in instantiation of default function argument}} +} + // PR5283 namespace PR5283 { template struct A { @@ -131,3 +143,4 @@ namespace pr5301 { h(0); } } +