From: John McCall Date: Fri, 11 Dec 2015 01:56:36 +0000 (+0000) Subject: Correctly type-check the default arguments of local functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=40ef2b7531472c41212c4719a9294aeb7bddebbc;p=clang Correctly type-check the default arguments of local functions when eagerly instantiating them. rdar://23721638 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255325 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 3a3f6323d4..ac99a25470 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1680,8 +1680,11 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, Sema::ContextRAII SavedContext(*this, OwningFunc); LocalInstantiationScope Local(*this); ExprResult NewArg = SubstExpr(Arg, TemplateArgs); - if (NewArg.isUsable()) - NewParm->setDefaultArg(NewArg.get()); + if (NewArg.isUsable()) { + // It would be nice if we still had this. + SourceLocation EqualLoc = NewArg.get()->getLocStart(); + SetParamDefaultArgument(NewParm, NewArg.get(), EqualLoc); + } } else { // FIXME: if we non-lazily instantiated non-dependent default args for // non-dependent parameter types we could remove a bunch of duplicate diff --git a/test/SemaTemplate/instantiate-local-class.cpp b/test/SemaTemplate/instantiate-local-class.cpp index c0ea6a0bc8..a61af7a5af 100644 --- a/test/SemaTemplate/instantiate-local-class.cpp +++ b/test/SemaTemplate/instantiate-local-class.cpp @@ -448,3 +448,30 @@ namespace PR21332 { } template void f7(); } + +// rdar://23721638: Ensure that we correctly perform implicit +// conversions when instantiating the default arguments of local functions. +namespace rdar23721638 { + struct A { + A(const char *) = delete; // expected-note 2 {{explicitly marked deleted here}} + }; + + template void foo() { + struct Inner { // expected-note {{in instantiation}} + void operator()(T a = "") {} // expected-error {{conversion function from 'const char [1]' to 'rdar23721638::A' invokes a deleted function}} + // expected-note@-1 {{passing argument to parameter 'a' here}} + // expected-note@-2 {{candidate function not viable}} + }; + Inner()(); // expected-error {{no matching function}} + } + template void foo(); // expected-note 2 {{in instantiation}} + + template void bar() { + auto lambda = [](T a = "") {}; // expected-error {{conversion function from 'const char [1]' to 'rdar23721638::A' invokes a deleted function}} + // expected-note@-1 {{passing argument to parameter 'a' here}} + // expected-note@-2 {{candidate function not viable}} + // expected-note@-3 {{conversion candidate of type}} + lambda(); // expected-error {{no matching function}} + } + template void bar(); // expected-note {{in instantiation}} +}