Author: rjmccall Date: Thu Dec 10 19:56:36 2015 New Revision: 255325 URL: http://llvm.org/viewvc/llvm-project?rev=255325&view=rev Log: Correctly type-check the default arguments of local functions when eagerly instantiating them.
rdar://23721638 Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=255325&r1=255324&r2=255325&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu Dec 10 19:56:36 2015 @@ -1680,8 +1680,11 @@ ParmVarDecl *Sema::SubstParmVarDecl(Parm 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 Modified: cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp?rev=255325&r1=255324&r2=255325&view=diff ============================================================================== --- cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp (original) +++ cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp Thu Dec 10 19:56:36 2015 @@ -448,3 +448,30 @@ namespace PR21332 { } template void f7<int>(); } + +// 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 <typename T> 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<A>(); // expected-note 2 {{in instantiation}} + + template <typename T> 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<A>(); // expected-note {{in instantiation}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits