[clang] [clang][Sema] Add regression test for GH91131 (PR #236018)

Artem Ershov via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 23:57:46 PDT 2026


https://github.com/iam28th created https://github.com/llvm/llvm-project/pull/236018

The assersion failure, reported in https://github.com/llvm/llvm-project/issues/91131, doesn't fire since https://github.com/llvm/llvm-project/pull/92597 ; but that PR does not include a test for this case.

Add a SemaTemplate regression test that verifies the invalid program emits the expected diagnostics without crashing.

Note that a minimum patch to fix the original crash would be this:
https://github.com/iam28th/llvm-project/commit/9d498c7e984e7c3a4f38a76d079146c4b290861a

Fixes https://github.com/llvm/llvm-project/issues/91131

>From 34fb71b6d1e6fe4688073c1fdaa1096eb6303931 Mon Sep 17 00:00:00 2001
From: iam28th <artyom28th at gmail.com>
Date: Tue, 27 Oct 2026 09:48:56 +0300
Subject: [PATCH] [clang][Sema] Add regression test for GH91131

---
 clang/test/SemaTemplate/gh91131.cpp | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 clang/test/SemaTemplate/gh91131.cpp

diff --git a/clang/test/SemaTemplate/gh91131.cpp b/clang/test/SemaTemplate/gh91131.cpp
new file mode 100644
index 00000000000000..2ea364562c6064
--- /dev/null
+++ b/clang/test/SemaTemplate/gh91131.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template <typename T>
+struct B : T {};
+
+template <typename T>
+struct A : B<T> {};
+
+// expected-note at +1 {{attempt to specialize declaration here}}
+struct C {}; // first declaration (valid and complete)
+
+// expected-error at +1 {{extraneous 'template<>' in declaration of struct 'C'}}
+template <>
+struct C {}; // second declaration (invalid)
+// expected-error at -1 {{specialization of member 'C' does not specialize an instantiated member}}
+
+// crash before pull 92597:
+// definition for C was retrieved via TagDecl::getDefinition (inherited by RecordDecl),
+// which returned the first declaration because that declaraion is a complete definition;
+// that definition wasn't invalid, so A<C> wasn't invalid as well;
+// later assertion failed when layout for A<C> was built.
+//
+// was fixed in pull 92597: because it checks definition retrieved via CXXRecordDecl::getDefinition.
+A<C> v;



More information about the cfe-commits mailing list