[clang] [Clang] Ensure NTTP decls are traversed when building parameter mapping (PR #246548)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 26 18:50:06 PST 2026


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

They were not traversed when their types were dependent, hence we were not checking them correctly.

Mirrors fixes in 92d8313

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

>From f0e378066d6b84307b3242a45251c7e1660d055c Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Fri, 27 Nov 2026 10:47:03 +0800
Subject: [PATCH] [Clang] Ensure NTTP decls are traversed when building
 parameter mapping

They were not traversed when their types were dependent, hence we were
not checking them correctly.

Mirrors 92d8313
---
 clang/docs/ReleaseNotes.md               |  2 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp |  6 ++++++
 clang/test/SemaTemplate/concepts.cpp     | 23 +++++++++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 409d2459b0580b..e5bdec5fe346af 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -934,6 +934,8 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
 
 - Instantiate constexpr functions as needed before they are evaluated. (#GH73232) (#GH35052) (#GH100897)
 
+- Fixed a concept bug where dependent NTTP types were not built into parameter mapping. (#GH246501)
+
 - Fixed lambdas with specifiers or attributes after the capture list being
   misparsed as function declarations in direct-initialization contexts under
   `-fms-extensions` or in HLSL mode.
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 3e1819c9134ffb..9c0581f10abc41 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -6912,6 +6912,12 @@ struct MarkUsedTemplateParameterVisitor : DynamicRecursiveASTVisitor {
     return true;
   }
 
+  bool VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *NTTP) override {
+    if (NTTP->getDepth() == Depth)
+      Used[NTTP->getIndex()] = true;
+    return true;
+  }
+
   bool TraverseSizeOfPackExpr(SizeOfPackExpr *SOPE) override {
     return TraverseDecl(SOPE->getPack());
   }
diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp
index 4e7001b5c519df..59eb4ce096a73f 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -2143,3 +2143,26 @@ void bar() {
 }
 } // namespace N2
 }
+
+namespace GH246501 {
+
+template<auto... Vs>
+concept Two = sizeof...(Vs) == 2; // #GH246501_Two
+
+template<auto... Vs>
+  requires Two<Vs...> // #GH246501_Use
+struct S {};
+
+S<1> s;
+// expected-error at -1 {{not satisfied}}
+// expected-note@#GH246501_Use {{does not satisfy}}
+// expected-note@#GH246501_Two {{false}}
+
+S<1, 2> s2;
+
+S<1, 2, 3> s3;
+// expected-error at -1 {{not satisfied}}
+// expected-note@#GH246501_Use {{evaluated to false}}
+// expected-note@#GH246501_Two {{false}}
+
+}



More information about the cfe-commits mailing list