https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/237843

We always consider undeduced specializations as NeedDefinition, despite 
UsableInConstantExpr.

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

>From 0340d599c7f3bbbdd70799349086896ef4b1845d Mon Sep 17 00:00:00 2001
From: Younan Zhang <[email protected]>
Date: Mon, 2 Nov 2026 14:03:13 +0800
Subject: [PATCH] [Clang] Fix variable template instantiation

We always consider undeduced specializations as NeedDefinition, despite
UsableInConstantExpr.
---
 clang/lib/Sema/SemaExpr.cpp       | 3 +--
 clang/test/CodeGenCXX/gh56652.cpp | 1 +
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e29caaab8e3f30..982d478f57ae4d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -20977,8 +20977,7 @@ static void DoMarkVarDeclReferenced(
 
   bool NeedDefinition =
       OdrUse == OdrUseContext::Used || NeededForConstantEvaluation ||
-      (TSK != clang::TSK_Undeclared && !UsableInConstantExpr &&
-       Var->getType()->isUndeducedType());
+      (TSK != clang::TSK_Undeclared && Var->getType()->isUndeducedType());
 
   assert(!isa<VarTemplatePartialSpecializationDecl>(Var) &&
          "Can't instantiate a partial template specialization.");
diff --git a/clang/test/CodeGenCXX/gh56652.cpp 
b/clang/test/CodeGenCXX/gh56652.cpp
index 06a496e320bfc1..066331030ba25a 100644
--- a/clang/test/CodeGenCXX/gh56652.cpp
+++ b/clang/test/CodeGenCXX/gh56652.cpp
@@ -33,6 +33,7 @@ template <class> static void c() noexcept(noexcept(b<int>)) {}
 
 void test() { a<>::c<int>(); }
 
+static_assert(sizeof(S<>::b<int>) == sizeof(int));
 
 }
 

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

Reply via email to