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

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


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/246548.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.md (+2) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+6) 
- (modified) clang/test/SemaTemplate/concepts.cpp (+23) 


``````````diff
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}}
+
+}

``````````

</details>


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


More information about the cfe-commits mailing list