Author: babadany2999 Date: 2026-08-05T11:57:24Z New Revision: b5b34ff378896572ccac8c77445f8e90c0547988
URL: https://github.com/llvm/llvm-project/commit/b5b34ff378896572ccac8c77445f8e90c0547988 DIFF: https://github.com/llvm/llvm-project/commit/b5b34ff378896572ccac8c77445f8e90c0547988.diff LOG: [Clang][Sema] Fix an assertion crash when instantiating a nested requirement (#213660) We should check if the expression is valid before getConstraintExpr. Fixes #213575 Added: Modified: clang/docs/ReleaseNotes.md clang/lib/Sema/SemaTemplateInstantiate.cpp clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index a00b725143d49..66346bf40193f 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) - Clang now defines the GCC-compatible predefined macro `__SIG_ATOMIC_TYPE__`. (#GH213895) #### 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
