[clang] [Clang] Adjust NTTP depths in IsAtLeastAsConstrained (PR #209445)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 14 04:24:26 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Younan Zhang (zyn0217)
<details>
<summary>Changes</summary>
The default transform for NTTP, which is no-op, doesn't help if we need to adjust their depths when comparing constraints.
Fixes https://github.com/llvm/llvm-project/issues/182671
---
Full diff: https://github.com/llvm/llvm-project/pull/209445.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (+1)
- (modified) clang/lib/Sema/SemaConcept.cpp (+24)
- (modified) clang/test/SemaCXX/concepts-subsumption.cpp (+18-1)
``````````diff
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..99b4e61c5e0a1 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -276,6 +276,30 @@ 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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/209445
More information about the cfe-commits
mailing list