https://github.com/w007878 updated 
https://github.com/llvm/llvm-project/pull/201506

>From 62c448c34c3cb06a54050228ab822b99f888fc67 Mon Sep 17 00:00:00 2001
From: Fan Mo <[email protected]>
Date: Wed, 3 Jun 2026 23:33:18 -0500
Subject: [PATCH 1/3] fix: allow invalid case in assertion

---
 clang/lib/Sema/SemaTemplate.cpp      |  5 +++--
 clang/test/SemaTemplate/GH201490.cpp | 10 ++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/GH201490.cpp

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 8c94a1ad39208..23d47249dfd88 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2247,9 +2247,10 @@ DeclResult Sema::CheckClassTemplate(
     NewTemplate->setModulePrivate();
 
   if (IsMemberSpecialization) {
-    assert(PrevClassTemplate &&
+    assert((PrevClassTemplate || Invalid) &&
            "Member specialization without a primary template?");
-    NewTemplate->setMemberSpecialization();
+    if (PrevClassTemplate)
+      NewTemplate->setMemberSpecialization();
   }
 
   // Set the access specifier.
diff --git a/clang/test/SemaTemplate/GH201490.cpp 
b/clang/test/SemaTemplate/GH201490.cpp
new file mode 100644
index 0000000000000..13f05a56f41ab
--- /dev/null
+++ b/clang/test/SemaTemplate/GH201490.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// regression test for https://github.com/llvm/llvm-project/issues/201490
+template<class T> struct A {};
+template<class T> struct B : A<T> {};
+template<> template<class T> class A<int>::B {}; // 
expected-error{{out-of-line definition of 'B' does not match any declaration in 
'A<int>'}}
+
+// A legitimate member class template explicit specialization
+template<class T> struct C { template<class U> struct D; };
+  template<> template<class U> struct C<int>::D {};

>From f2fb0ba4f3ebf53658907cdf12d75ac749750f40 Mon Sep 17 00:00:00 2001
From: Fan Mo <[email protected]>
Date: Thu, 11 Jun 2026 01:33:47 -0500
Subject: [PATCH 2/3] add release note

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5e7a0c76d4594..cb8475de21d27 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -811,6 +811,7 @@ Miscellaneous Clang Crashes Fixed
 - Fixed an assertion failure in ``isAtEndOfMacroExpansion`` on macro 
expansions crossing the boundary of two fileIDs. (#GH115007), (#GH21755)
 - Fixed an assertion failure when ``__builtin_dump_struct`` is used with an
   immediate-escalated callable. (#GH192846)
+- Fixed a crash when diagnosing an invalid out-of-line definition of a member 
class template. (#GH201490)
 
 OpenACC Specific Changes
 ------------------------

>From 10e19f9196ad94dd21169b943bff9dafedc9f233 Mon Sep 17 00:00:00 2001
From: Fan Mo <[email protected]>
Date: Fri, 12 Jun 2026 23:29:33 -0500
Subject: [PATCH 3/3] consolidate test case

---
 clang/test/SemaTemplate/GH201490.cpp                   | 10 ----------
 .../test/SemaTemplate/instantiate-member-template.cpp  |  6 ++++++
 2 files changed, 6 insertions(+), 10 deletions(-)
 delete mode 100644 clang/test/SemaTemplate/GH201490.cpp

diff --git a/clang/test/SemaTemplate/GH201490.cpp 
b/clang/test/SemaTemplate/GH201490.cpp
deleted file mode 100644
index 13f05a56f41ab..0000000000000
--- a/clang/test/SemaTemplate/GH201490.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-// regression test for https://github.com/llvm/llvm-project/issues/201490
-template<class T> struct A {};
-template<class T> struct B : A<T> {};
-template<> template<class T> class A<int>::B {}; // 
expected-error{{out-of-line definition of 'B' does not match any declaration in 
'A<int>'}}
-
-// A legitimate member class template explicit specialization
-template<class T> struct C { template<class U> struct D; };
-  template<> template<class U> struct C<int>::D {};
diff --git a/clang/test/SemaTemplate/instantiate-member-template.cpp 
b/clang/test/SemaTemplate/instantiate-member-template.cpp
index 4c74f5fb938b6..475480cc247af 100644
--- a/clang/test/SemaTemplate/instantiate-member-template.cpp
+++ b/clang/test/SemaTemplate/instantiate-member-template.cpp
@@ -259,3 +259,9 @@ namespace rdar8986308 {
   }
 
 }
+
+namespace GH201490 {
+  template<class T> struct A {};
+  template<class T> struct B : A<T> {};
+  template<> template<class T> class A<int>::B {}; // 
expected-error{{out-of-line definition of 'B' does not match any declaration in 
'A<int>'}}
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to