Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -8195,6 +8195,7 @@ FunctionTemplateDecl *FunctionTemplate = nullptr; bool isMemberSpecialization = false; bool isFunctionTemplateSpecialization = false; + bool HasFabricatedTemplateSpecializationTemplateParams = false; bool isDependentClassScopeExplicitSpecialization = false; bool HasExplicitTemplateArgs = false; @@ -8303,6 +8304,8 @@ } else { // This is a function template specialization. isFunctionTemplateSpecialization = true; + if (Invalid && TemplateParams->getLAngleLoc().isInvalid()) + HasFabricatedTemplateSpecializationTemplateParams = true; // For source fidelity, store all the template param lists. if (TemplateParamLists.size() > 0) NewFD->setTemplateParameterListsInfo(Context, TemplateParamLists); @@ -8874,7 +8877,8 @@ diag::ext_function_specialization_in_class : diag::err_function_specialization_in_class) << NewFD->getDeclName(); - } else if (CheckFunctionTemplateSpecialization(NewFD, + } else if (!HasFabricatedTemplateSpecializationTemplateParams && + CheckFunctionTemplateSpecialization(NewFD, (HasExplicitTemplateArgs ? &TemplateArgs : nullptr), Previous)) Index: test/SemaTemplate/deduction-crash.cpp =================================================================== --- test/SemaTemplate/deduction-crash.cpp +++ test/SemaTemplate/deduction-crash.cpp @@ -144,3 +144,20 @@ template int n; // expected-error +{{}} expected-note {{}} int k = n; } + +namespace deduceFunctionSpecializationForInvalidOutOfLineFunction { + +template +struct SourceSelectionRequirement { + template + OutputT evaluateSelectionRequirement(InputT &&Value) { + } +}; + +template +OutputT SourceSelectionRequirement:: +evaluateSelectionRequirement(InputT &&Value) { // expected-error {{cannot specialize a member of an unspecialized template}} + return Value; +} + +} Index: test/SemaTemplate/explicit-specialization-member.cpp =================================================================== --- test/SemaTemplate/explicit-specialization-member.cpp +++ test/SemaTemplate/explicit-specialization-member.cpp @@ -38,24 +38,20 @@ template template - void Baz::bar() { // expected-note {{couldn't infer template argument 'N'}} + void Baz::bar() { } - // FIXME: We shouldn't try to match this against a prior declaration if - // template parameter matching failed. template - void Baz::bar<0>() { // expected-error {{cannot specialize a member of an unspecialized template}} \ - // expected-error {{no function template matches}} + void Baz::bar<0>() { // expected-error {{cannot specialize a member of an unspecialized template}} } } namespace PR19340 { template struct Helper { - template static void func(const T *m) {} // expected-note {{failed template argument deduction}} + template static void func(const T *m) {} }; -template void Helper::func<2>() {} // expected-error {{cannot specialize a member}} \ - // expected-error {{no function template matches}} +template void Helper::func<2>() {} // expected-error {{cannot specialize a member}} } namespace SpecLoc {