Author: Younan Zhang
Date: 2026-07-14T22:14:14+08:00
New Revision: e731908c4f84e04a5bfbe2784231f072aac90fe6

URL: 
https://github.com/llvm/llvm-project/commit/e731908c4f84e04a5bfbe2784231f072aac90fe6
DIFF: 
https://github.com/llvm/llvm-project/commit/e731908c4f84e04a5bfbe2784231f072aac90fe6.diff

LOG: [Clang] Adjust NTTP depths in IsAtLeastAsConstrained (#209445)

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

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.md
    clang/lib/Sema/SemaConcept.cpp
    clang/test/SemaCXX/concepts-subsumption.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 465f1eec8c05f..4670244baaf81 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -102,6 +102,8 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
 
 ### Bug Fixes in This Version
 
+- Fixed a constraint comparison bug in partial ordering. (#GH182671)
+
 #### Bug Fixes to Compiler Builtins
 
 #### Bug Fixes to Attribute Support

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@-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@-1 {{'T' declared here}}
+
+// FIXME: The diagnostics are not great
+using Y = Wrapper2<A>;
+// expected-error@-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.


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

Reply via email to