https://github.com/babadany2999 updated 
https://github.com/llvm/llvm-project/pull/213660

>From 379486b9e974bb1546f72215b6df7efb86490cae Mon Sep 17 00:00:00 2001
From: Baba Dan Constantin <[email protected]>
Date: Mon, 3 Aug 2026 15:36:58 +0300
Subject: [PATCH] [Clang][Sema] Fix an assertion crash when instantiating a
 nested requirement with an invalid constraint. (#GH213575)

---
 clang/docs/ReleaseNotes.md                       |  1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp       |  3 ++-
 .../expr.prim.req/nested-requirement.cpp         | 16 ++++++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index a38b99ff8e075..fac0526ae42da 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -365,6 +365,7 @@ features cannot lower the translation-unit ABI level;
 - Fixed a bug where `__func__`, `__PRETTY_FUNCTION__` and `__FUNCTION__` were 
not resolving to the proper function when inside a lambda return type 
(#GH211811)
 - Fixed USR generation for declarations whose signature mentions a class-type
   non-type template parameter. (#GH212351)
+- Fixed an assertion crash when instantiating a nested requirement with an 
invalid constraint. (#GH213575)
 
 #### Bug Fixes to Compiler Builtins
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 2cf2a4f85f830..21d68f765bdaf 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2832,7 +2832,6 @@ TemplateInstantiator::TransformNestedRequirement(
 
   ASTContext &C = SemaRef.Context;
 
-  Expr *Constraint = Req->getConstraintExpr();
   ConstraintSatisfaction Satisfaction;
 
   auto NestedReqWithDiag = [&C, this](Expr *E,
@@ -2852,6 +2851,8 @@ TemplateInstantiator::TransformNestedRequirement(
     return Req;
   }
 
+  Expr *Constraint = Req->getConstraintExpr();
+
   if (!getEvaluateConstraints()) {
     ExprResult TransConstraint = TransformExpr(Req->getConstraintExpr());
     if (TransConstraint.isInvalid() || !TransConstraint.get())
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
index 7b58150eaaf84..d3328f7a0851c 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -183,3 +183,19 @@ template <typename> class j {
 };
 template <> j(); // expected-error {{deduction guide declaration without 
trailing return type}}
 }
+
+namespace GH213575 {
+struct S {};
+template <typename T> bar C; // expected-error {{unknown type name 'bar'}}
+
+template <typename U> auto foo() {
+  return []<typename T>(
+             T, bool b = requires { C<T>; }) {
+    static_assert(requires { requires C<U>; }); // expected-error {{static 
assertion failed due to requirement 'requires { requires <<error-expression>>; 
}'}}
+    return 0;
+  };
+}
+
+auto baz = foo<int>();
+int qux = baz(S{}); // expected-note {{in instantiation of function template 
specialization 'GH213575::foo()::(lambda)::operator()<GH213575::S>' requested 
here}}
+}

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

Reply via email to