diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 44d5f348ed2d5..ba5620deae439 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -471,6 +471,8 @@ Bug Fixes to C++ Support - Fixed an issue deducing non-type template arguments of reference type. (#GH73460) - Fixed an issue in constraint evaluation, where type constraints on the lambda expression containing outer unexpanded parameters were not correctly expanded. (#GH101754) +- Fixes crashes with function template member specializations, and increases + conformance of explicit instantiation behaviour with MSVC. (#GH111266) - Fixed a bug in constraint expression comparison where the ``sizeof...`` expression was not handled properly in certain friend declarations. (#GH93099) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 898255ff7c6a3..4ce47d8c1ee76 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -4206,18 +4206,14 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, if (Function->hasAttr()) continue; - MemberSpecializationInfo *MSInfo = - Function->getMemberSpecializationInfo(); - assert(MSInfo && "No member specialization information?"); - if (MSInfo->getTemplateSpecializationKind() - == TSK_ExplicitSpecialization) + TemplateSpecializationKind PrevTSK = + Function->getTemplateSpecializationKind(); + if (PrevTSK == TSK_ExplicitSpecialization) continue; - if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, - Function, - MSInfo->getTemplateSpecializationKind(), - MSInfo->getPointOfInstantiation(), - SuppressNew) || + if (CheckSpecializationInstantiationRedecl( + PointOfInstantiation, TSK, Function, PrevTSK, + Function->getPointOfInstantiation(), SuppressNew) || SuppressNew) continue; diff --git a/clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp b/clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp index e1f3ab37ad947..aacc092c2c66c 100644 --- a/clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp +++ b/clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp @@ -156,7 +156,13 @@ namespace UsesThis { auto h() -> decltype(this); // expected-error {{'this' cannot be used in a static member function declaration}} }; - template struct A; // expected-note 3{{in instantiation of}} + template struct A; // expected-note {{in instantiation of}} + template<> template<> void A::f(); + template<> template<> void A::g(); + void test1() { + A().f(); // expected-note {{in instantiation of}} + A().g(); // expected-note {{in instantiation of}} + } template struct Foo { @@ -390,7 +396,12 @@ namespace UsesThis { } }; - template struct D; // expected-note 2{{in instantiation of}} + template struct D; + + void test2() { + D().non_static_spec(0); // expected-note {{in instantiation of}} + D().static_spec(0); // expected-note {{in instantiation of}} + } template struct E : T { @@ -574,6 +585,23 @@ namespace UsesThis { } }; - template struct E; // expected-note 2{{in instantiation of}} + template struct E; + void test3() { + E().non_static_spec(0); // expected-note {{in instantiation of}} + E().static_spec(0); // expected-note {{in instantiation of}} + } } + +namespace GH111266 { + template struct S { + template auto foo(); + template<> auto foo<1>() { + return [](auto x) { return x; }; + } + }; + template struct S; + void test() { + S().foo<1>(); + } +} // namespace GH111266