Author: Ebin Jose Date: 2025-12-16T13:56:30Z New Revision: bbbba9c07c65782db54b178eaae36ccc0964420e
URL: https://github.com/llvm/llvm-project/commit/bbbba9c07c65782db54b178eaae36ccc0964420e DIFF: https://github.com/llvm/llvm-project/commit/bbbba9c07c65782db54b178eaae36ccc0964420e.diff LOG: [CLANG] Fixes the crash on the use of nested requirements in require expressions (#169876) Fixes #165386 Nested requirements in requires-expressions must be constant expressions. Previously, using an invented parameter in a nested requirement caused a crash. Now emit a clear diagnostic and recover. Added: clang/test/SemaCXX/requires-nested-non-constant.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExprCXX.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c39fe6e98b176..9f477a8f8b3ff 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -611,6 +611,7 @@ Bug Fixes to C++ Support - Fixed an issue where templates prevented nested anonymous records from checking the deletion of special members. (#GH167217) - Fixed spurious diagnoses of certain nested lambda expressions. (#GH149121) (#GH156579) - Fix the result of ``__is_pointer_interconvertible_base_of`` when arguments are qualified and passed via template parameters. (#GH135273) +- Fixed a crash when evaluating nested requirements in requires-expressions that reference invented parameters. (#GH166325) - Fixed a crash when standard comparison categories (e.g. ``std::partial_ordering``) are defined with incorrect static member types. (#GH170015) (#GH56571) Bug Fixes to AST Handling diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 70ec6a3a96b10..965ad55465db7 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -7965,7 +7965,9 @@ concepts::Requirement *Sema::ActOnNestedRequirement(Expr *Constraint) { concepts::NestedRequirement * Sema::BuildNestedRequirement(Expr *Constraint) { ConstraintSatisfaction Satisfaction; + LocalInstantiationScope Scope(*this); if (!Constraint->isInstantiationDependent() && + !Constraint->isValueDependent() && CheckConstraintSatisfaction(nullptr, AssociatedConstraint(Constraint), /*TemplateArgs=*/{}, Constraint->getSourceRange(), Satisfaction)) diff --git a/clang/test/SemaCXX/requires-nested-non-constant.cpp b/clang/test/SemaCXX/requires-nested-non-constant.cpp new file mode 100644 index 0000000000000..b5b8bdbf5a9dc --- /dev/null +++ b/clang/test/SemaCXX/requires-nested-non-constant.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s + +template <class C> class A { + void f() { + auto result = []() constexpr { + return requires (int x) { // expected-note {{declared here}} + requires (x > 0) && (x < 10); // expected-error {{substitution into constraint expression resulted in a non-constant expression}} \ + // expected-note {{while checking the satisfaction of nested requirement requested here}} \ + // expected-note {{function parameter 'x' with unknown value cannot be used in a constant expression}} + }; + }(); + } +}; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
