[clang] [Clang] Handle unsatisfied NestedRequirement correctly (PR #223001)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 12 07:50:19 PDT 2026
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/223001
>From cbbd57fba2f3f57f82b4598e8825601292fcbb49 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Sat, 12 Sep 2026 01:45:16 +0800
Subject: [PATCH 1/2] [Clang] Handle unsatisfied NestedRequirement correctly
Sema::BuildNestedRequirement(Expr *Constraint) built an incorrect
NestedRequirement even when unsatisfied. It was never triggered because
they are never diagnosed (we didn't diagnose concept details for static_assert
until ab896c6c6f2) and the other error handlings were done properly in
instantiator.
---
clang/lib/Sema/SemaExprCXX.cpp | 9 +++++++++
clang/test/SemaCXX/concept-crash-on-diagnostic.cpp | 13 +++++++++++++
2 files changed, 22 insertions(+)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index cc9f85e2bb0cb..c3dee56d8af78 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8175,6 +8175,15 @@ Sema::BuildNestedRequirement(Expr *Constraint) {
/*TemplateArgs=*/{},
Constraint->getSourceRange(), Satisfaction))
return nullptr;
+
+ if (!Satisfaction.IsSatisfied) {
+ SmallString<128> Entity;
+ llvm::raw_svector_ostream OS(Entity);
+ Constraint->printPretty(OS, nullptr, SemaRef.getPrintingPolicy());
+ return new (Context) concepts::NestedRequirement(
+ Context, Context.backupStr(Entity), std::move(Satisfaction));
+ }
+
return new (Context) concepts::NestedRequirement(Context, Constraint,
Satisfaction);
}
diff --git a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
index d3ac650fd8c82..b0b1e1e3b2bb5 100644
--- a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
+++ b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
@@ -73,3 +73,16 @@ namespace GH138823 {
void test() { bar(1); }
}
+
+namespace GH222954 {
+
+template <typename T> struct foo {};
+template <typename T>
+concept bar = foo<T>::baz;
+
+static_assert(requires { requires bar<int>; });
+// expected-error at -1 {{static assertion failed}}
+// expected-note at -2 {{because 'int' does not satisfy 'bar'}}
+// expected-note at -4 {{because 'bar<int>' would be invalid}}
+
+}
>From 476621ad6ce6f3ebe7f88cc47368c122424e0c80 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Sat, 12 Sep 2026 22:49:51 +0800
Subject: [PATCH 2/2] Fix lots of CI failures
---
clang/lib/Sema/SemaExprCXX.cpp | 2 +-
clang/test/SemaCXX/concept-crash-on-diagnostic.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c3dee56d8af78..5b41b2288e99f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8176,7 +8176,7 @@ Sema::BuildNestedRequirement(Expr *Constraint) {
Constraint->getSourceRange(), Satisfaction))
return nullptr;
- if (!Satisfaction.IsSatisfied) {
+ if (Satisfaction.HasSubstitutionFailure()) {
SmallString<128> Entity;
llvm::raw_svector_ostream OS(Entity);
Constraint->printPretty(OS, nullptr, SemaRef.getPrintingPolicy());
diff --git a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
index b0b1e1e3b2bb5..a021267b45d2f 100644
--- a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
+++ b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
@@ -83,6 +83,6 @@ concept bar = foo<T>::baz;
static_assert(requires { requires bar<int>; });
// expected-error at -1 {{static assertion failed}}
// expected-note at -2 {{because 'int' does not satisfy 'bar'}}
-// expected-note at -4 {{because 'bar<int>' would be invalid}}
+// expected-note at -5 {{because 'bar<int>' would be invalid}}
}
More information about the cfe-commits
mailing list