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 class j { }; template <> j(); // expected-error {{deduction guide declaration without trailing return type}} } + +namespace GH213575 { +struct S {}; +template bar C; // expected-error {{unknown type name 'bar'}} + +template auto foo() { + return []( + T, bool b = requires { C; }) { + static_assert(requires { requires C; }); // expected-error {{static assertion failed due to requirement 'requires { requires <>; }'}} + return 0; + }; +} + +auto baz = foo(); +int qux = baz(S{}); // expected-note {{in instantiation of function template specialization 'GH213575::foo()::(lambda)::operator()' requested here}} +}