https://github.com/HamzaHassanain updated 
https://github.com/llvm/llvm-project/pull/174281

>From aafd57e112ea07a66e2864c9034ac8bbc328c0b2 Mon Sep 17 00:00:00 2001
From: Hamza Hassanain <[email protected]>
Date: Sat, 3 Jan 2026 17:07:05 +0200
Subject: [PATCH 1/7] [Clang][Sema] reject undeduced static members without
 init

---
 clang/lib/Sema/SemaDecl.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 11323803e1910..50a6a4176d1ec 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14337,8 +14337,18 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
         DeduceVariableDeclarationType(Var, false, nullptr))
       return;
 
+    Type = Var->getType();
     this->CheckAttributesOnDeducedType(RealDecl);
 
+    if (auto *Deduced = Type->getContainedDeducedType()) {
+      if (Var->isStaticDataMember() && Deduced->getDeducedType().isNull()) {
+        Diag(Var->getLocation(), diag::err_auto_var_requires_init)
+            << Var->getDeclName() << Type;
+        Var->setInvalidDecl();
+        return;
+      }
+    }
+
     // C++11 [class.static.data]p3: A static data member can be declared with
     // the constexpr specifier; if so, its declaration shall specify
     // a brace-or-equal-initializer.

>From 74473fd4f581b5538e01b8a3c1e9e068f9c88831 Mon Sep 17 00:00:00 2001
From: Hamza Hassanain <[email protected]>
Date: Sat, 3 Jan 2026 17:31:34 +0200
Subject: [PATCH 2/7] [Clang][Test][SemaCXX] added alias tempalte static member
 hanlding test

---
 clang/test/SemaCXX/alias-template-static-member.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 clang/test/SemaCXX/alias-template-static-member.cpp

diff --git a/clang/test/SemaCXX/alias-template-static-member.cpp 
b/clang/test/SemaCXX/alias-template-static-member.cpp
new file mode 100644
index 0000000000000..0089aea33cc80
--- /dev/null
+++ b/clang/test/SemaCXX/alias-template-static-member.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template <class T>
+struct A {
+  template <class U>
+  using E = U;
+
+  static E u; // expected-error {{declaration of variable 'u' with deduced 
type 'E' requires an initializer}}
+};
+
+decltype(A<int>::u) a;
\ No newline at end of file

>From ddba6f35cd9aa85631f26388e618e41b279701d2 Mon Sep 17 00:00:00 2001
From: Hamza Hassanain <[email protected]>
Date: Sat, 3 Jan 2026 22:22:46 +0200
Subject: [PATCH 3/7] [Clang][Sema] Remove redundunt logic and call
 getContainedDeducedType instead?

---
 clang/lib/Sema/SemaDecl.cpp | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 50a6a4176d1ec..795bbda8ddc77 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14333,22 +14333,12 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
       return;
     }
 
-    if (Type->isUndeducedType() &&
+    if (Type->getContainedDeducedType() &&
         DeduceVariableDeclarationType(Var, false, nullptr))
       return;
 
-    Type = Var->getType();
     this->CheckAttributesOnDeducedType(RealDecl);
 
-    if (auto *Deduced = Type->getContainedDeducedType()) {
-      if (Var->isStaticDataMember() && Deduced->getDeducedType().isNull()) {
-        Diag(Var->getLocation(), diag::err_auto_var_requires_init)
-            << Var->getDeclName() << Type;
-        Var->setInvalidDecl();
-        return;
-      }
-    }
-
     // C++11 [class.static.data]p3: A static data member can be declared with
     // the constexpr specifier; if so, its declaration shall specify
     // a brace-or-equal-initializer.

>From c1792109fc5172db229cb85d20432d60fb12ba34 Mon Sep 17 00:00:00 2001
From: Hamza Hassanain <[email protected]>
Date: Sat, 3 Jan 2026 22:23:14 +0200
Subject: [PATCH 4/7] [Clang][docs] added a relase not

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2319ff13f7864..9da6ea13fe234 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -623,6 +623,10 @@ Bug Fixes to C++ Support
 - Fix the result of ``__is_pointer_interconvertible_base_of`` when arguments 
are qualified and passed via template parameters. (#GH135273)
 - Fixed a crash when evaluating nested requirements in requires-expressions 
that reference invented parameters. (#GH166325)
 - Fixed a crash when standard comparison categories (e.g. 
``std::partial_ordering``) are defined with incorrect static member types. 
(#GH170015) (#GH56571)
+- Fixed a crash where Clang would attempt to generate code for a static data 
+  member declared with an alias template without template arguments. 
+  Clang now correctly diagnoses this as an undeduced type and rejects 
+  the declaration. (#GH173349)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^

>From db0977236c86854af4bf413a718917f9b2864efb Mon Sep 17 00:00:00 2001
From: Hamza Hassanain <[email protected]>
Date: Sun, 4 Jan 2026 22:37:40 +0200
Subject: [PATCH 5/7] [clang][tests] added a missing newline

---
 clang/test/SemaCXX/alias-template-static-member.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/alias-template-static-member.cpp 
b/clang/test/SemaCXX/alias-template-static-member.cpp
index 0089aea33cc80..a8721a0cf6f05 100644
--- a/clang/test/SemaCXX/alias-template-static-member.cpp
+++ b/clang/test/SemaCXX/alias-template-static-member.cpp
@@ -8,4 +8,4 @@ struct A {
   static E u; // expected-error {{declaration of variable 'u' with deduced 
type 'E' requires an initializer}}
 };
 
-decltype(A<int>::u) a;
\ No newline at end of file
+decltype(A<int>::u) a;

>From ff66fc242b621db1327f62a5be41d76b3e86efb6 Mon Sep 17 00:00:00 2001
From: Hamza Hassanain <[email protected]>
Date: Tue, 6 Jan 2026 11:53:55 +0200
Subject: [PATCH 6/7] moved tests to alias-template.cpp, and enfored runs by
 c++ 20, maniaing older tests

---
 clang/test/SemaCXX/alias-template.cpp | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/clang/test/SemaCXX/alias-template.cpp 
b/clang/test/SemaCXX/alias-template.cpp
index b49d36a6267e6..f848530b51d49 100644
--- a/clang/test/SemaCXX/alias-template.cpp
+++ b/clang/test/SemaCXX/alias-template.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify -std=c++14 -fcxx-exceptions %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
+#if __cplusplus < 202002L
 namespace RedeclAliasTypedef {
   template<typename U> using T = int;
   template<typename U> using T = int;
@@ -198,3 +200,18 @@ int g = sfinae_me<int>(); // expected-error{{no matching 
function for call to 's
 namespace NullExceptionDecl {
 template<int... I> auto get = []() { try { } catch(...) {}; return I; }; // 
expected-error{{initializer contains unexpanded parameter pack 'I'}}
 }
+#endif
+
+#if __cplusplus >= 202002L
+namespace PR174281 {
+template <class T>
+struct A {
+  template <class U>
+  using E = U; // expected-note {{template is declared here}}
+  static E u2 = 0; // expected-error {{alias template 'E' requires template 
arguments; argument deduction only allowed for class templates or alias 
templates}}
+  static E u; // expected-error {{declaration of variable 'u' with deduced 
type 'E' requires an initializer}}
+};
+
+decltype(A<int>::u) a; // expected-note {{in instantiation of template class 
'PR174281::A<int>' requested here}}
+}
+#endif

>From b95e942f798daade7b77bf6b6353ab7aa0ed20d6 Mon Sep 17 00:00:00 2001
From: Hamza Hassanain <[email protected]>
Date: Tue, 6 Jan 2026 12:17:26 +0200
Subject: [PATCH 7/7] Delete
 clang/test/SemaCXX/alias-template-static-member.cpp

---
 clang/test/SemaCXX/alias-template-static-member.cpp | 11 -----------
 1 file changed, 11 deletions(-)
 delete mode 100644 clang/test/SemaCXX/alias-template-static-member.cpp

diff --git a/clang/test/SemaCXX/alias-template-static-member.cpp 
b/clang/test/SemaCXX/alias-template-static-member.cpp
deleted file mode 100644
index a8721a0cf6f05..0000000000000
--- a/clang/test/SemaCXX/alias-template-static-member.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
-
-template <class T>
-struct A {
-  template <class U>
-  using E = U;
-
-  static E u; // expected-error {{declaration of variable 'u' with deduced 
type 'E' requires an initializer}}
-};
-
-decltype(A<int>::u) a;

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

Reply via email to