[clang] [Clang] Adjust NTTP depths in IsAtLeastAsConstrained (PR #209445)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 14 05:54:07 PDT 2026
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/209445
>From 9ef7bc804c0ce57c07e248334b09da524fe78601 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Tue, 14 Jul 2026 19:18:25 +0800
Subject: [PATCH] [Clang] Adjust NTTP depths in IsAtLeastAsConstrained
---
clang/docs/ReleaseNotes.md | 1 +
clang/lib/Sema/SemaConcept.cpp | 25 +++++++++++++++++++++
clang/test/SemaCXX/concepts-subsumption.cpp | 19 +++++++++++++++-
3 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 9063e54b3e692..06fdb04ab95db 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -778,6 +778,7 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
- Fixed a preprocessor crash in `__has_cpp_attribute` on incomplete scoped attributes. (#GH178098)
- Fixes an assertion failure when evaluating `__underlying_type` on enum redeclarations. (#GH177943)
- Fixed an assertion failure caused by nested macro expansion during header-name lexing (`__has_embed(__has_include)`). (#GH178635)
+- Fixed a constraint comparison bug in partial ordering. (#GH182671)
- Clang now outputs relative paths of embeds for dependency output. (#GH161950)
- Fix the result type of a binary operation where both operands are 'void' l-values. (#GH111300)
- Fixed an assertion failure when evaluating `_Countof` on invalid `void`-typed operands. (#GH180893)
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 476910a9db528..8831a26224e7d 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -276,6 +276,31 @@ class AdjustConstraints : public TreeTransform<AdjustConstraints> {
return false;
return true;
}
+
+ ExprResult TransformDeclRefExpr(DeclRefExpr *E) {
+ NonTypeTemplateParmDecl *NTTP =
+ dyn_cast<NonTypeTemplateParmDecl>(E->getDecl());
+ if (!NTTP)
+ return inherited::TransformDeclRefExpr(E);
+
+ assert(E->getTemplateArgs() == nullptr &&
+ "Template arguments for NTTP decl?");
+ auto *TSI = inherited::TransformType(NTTP->getTypeSourceInfo());
+ if (!TSI)
+ return ExprError();
+
+ auto *D = NonTypeTemplateParmDecl::Create(
+ SemaRef.getASTContext(), NTTP->getDeclContext(),
+ NTTP->getInnerLocStart(), NTTP->getLocation(),
+ NTTP->getDepth() + TemplateDepth, NTTP->getPosition(),
+ NTTP->getIdentifier(), TSI->getType(), NTTP->isParameterPack(), TSI);
+
+ return DeclRefExpr::Create(
+ SemaRef.getASTContext(), E->getQualifierLoc(),
+ E->getTemplateKeywordLoc(), D, E->refersToEnclosingVariableOrCapture(),
+ E->getNameInfo(), TSI->getType(), E->getValueKind(), D,
+ /*TemplateArgs=*/nullptr, E->isNonOdrUse());
+ }
};
} // namespace
diff --git a/clang/test/SemaCXX/concepts-subsumption.cpp b/clang/test/SemaCXX/concepts-subsumption.cpp
index d9d5535e532f4..d00a8b973cb91 100644
--- a/clang/test/SemaCXX/concepts-subsumption.cpp
+++ b/clang/test/SemaCXX/concepts-subsumption.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
-// expected-no-diagnostics
+
namespace A {
template <typename T>
concept C = true;
@@ -32,6 +32,23 @@ constexpr int f() { return 1; }
static_assert(f<int>() == 0);
}
+namespace GH182671 {
+
+template<int N> concept Positive = N > 0;
+template<int N> requires Positive<N> struct A {};
+// expected-note at -1 {{'A' declared here}}
+template<template<int N> requires Positive<N> typename T> struct Wrapper {};
+using X = Wrapper<A>;
+
+template<template<int N> requires Positive<N + 1> typename T> struct Wrapper2 {};
+// expected-note at -1 {{'T' declared here}}
+
+// FIXME: The diagnostics are not great
+using Y = Wrapper2<A>;
+// expected-error at -1 {{template template argument 'A' is more constrained than template template parameter 'T'}}
+
+}
+
namespace GH122581 {
// Test that producing a Conjunctive Normal Form
// does not blow up exponentially.
More information about the cfe-commits
mailing list