https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/80656
>From 48211eb7778db8fb8af144d59adb2e0941957c4c Mon Sep 17 00:00:00 2001 From: Younan Zhang <zyn7...@gmail.com> Date: Mon, 5 Feb 2024 18:01:34 +0800 Subject: [PATCH 1/4] GH78524 --- clang/docs/ReleaseNotes.rst | 4 +++ clang/lib/Parse/ParseExprCXX.cpp | 6 ++++- .../Parser/cxx-concepts-requires-clause.cpp | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e634db3c718c9d..42348512326953 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -193,6 +193,10 @@ Bug Fixes to C++ Support - Fixed an out-of-bounds error caused by building a recovery expression for ill-formed function calls while substituting into constraints. (`#58548 <https://github.com/llvm/llvm-project/issues/58548>`_) +- Fixed an issue where template parameters of the nested abbreviated generic lambda within + a requires-clause lie at the same depth as those of the surrounding lambda. This, + in turn, results in the wrong template argument substitution during the constraint checking. + (`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_) - Fix incorrect code generation caused by the object argument of ``static operator()`` and ``static operator[]`` calls not being evaluated. Fixes (`#67976 <https://github.com/llvm/llvm-project/issues/67976>`_) - Fix crash and diagnostic with const qualified member operator new. diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index fd262ff31e661a..5c374d2eb452dc 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -1385,6 +1385,11 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( Diag(RAngleLoc, diag::err_lambda_template_parameter_list_empty); } else { + // We increase the template depth before recursing into a requires-clause. + // The abbreviated generic lambdas thereof could have different template + // depths, avoiding substituting into wrong template parameters during the + // satisfaction check. + ++CurTemplateDepthTracker; ExprResult RequiresClause; if (TryConsumeToken(tok::kw_requires)) { RequiresClause = @@ -1396,7 +1401,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( Actions.ActOnLambdaExplicitTemplateParameterList( Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause); - ++CurTemplateDepthTracker; } } diff --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp b/clang/test/Parser/cxx-concepts-requires-clause.cpp index 1ec1eefa128653..f268092728fdfe 100644 --- a/clang/test/Parser/cxx-concepts-requires-clause.cpp +++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp @@ -168,3 +168,30 @@ auto lambda4 = [] requires(sizeof(char) == 1){}; // expected-error {{expected bo #if __cplusplus <= 202002L // expected-warning@-2{{lambda without a parameter clause is a C++23 extension}} #endif + +namespace GH78524 { + +template <typename T> T Foo; + +template <typename T> auto C(Foo<T>); + +template <typename T> struct D { + decltype(T()(C<T>)) Type; +}; + +template <typename T, typename U> D<T> G(T, U) { return {}; } + +struct E {}; + +void F() { + G([]<typename T> +// ~~~~~~~~~~ T: 0,0 + requires requires { [](auto...) {}; }(T) +// ~~~~ auto: 1,0 + { return T(); }, + E{}); +} + +int a = []<int=0> requires requires { [](auto){}; } { return 0; }(); + +} // namespace GH78524 >From c550f3a5f519f11634e106cb40a3c53fa22b345e Mon Sep 17 00:00:00 2001 From: Younan Zhang <zyn7...@gmail.com> Date: Mon, 5 Feb 2024 21:00:40 +0800 Subject: [PATCH 2/4] Remove a trailing whitespace --- clang/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 42348512326953..1c427618ce44bd 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -196,7 +196,7 @@ Bug Fixes to C++ Support - Fixed an issue where template parameters of the nested abbreviated generic lambda within a requires-clause lie at the same depth as those of the surrounding lambda. This, in turn, results in the wrong template argument substitution during the constraint checking. - (`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_) + (`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_) - Fix incorrect code generation caused by the object argument of ``static operator()`` and ``static operator[]`` calls not being evaluated. Fixes (`#67976 <https://github.com/llvm/llvm-project/issues/67976>`_) - Fix crash and diagnostic with const qualified member operator new. >From e305e4dc4c127cb18fb6fdb26fbc2148ec97989a Mon Sep 17 00:00:00 2001 From: Younan Zhang <zyn7...@gmail.com> Date: Sun, 11 Feb 2024 23:40:24 +0800 Subject: [PATCH 3/4] Address comments --- clang/lib/Parse/ParseExprCXX.cpp | 9 +++++++-- clang/test/Parser/cxx-concepts-requires-clause.cpp | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 5c374d2eb452dc..7ab38e59ac4bf8 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -1386,8 +1386,13 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( diag::err_lambda_template_parameter_list_empty); } else { // We increase the template depth before recursing into a requires-clause. - // The abbreviated generic lambdas thereof could have different template - // depths, avoiding substituting into wrong template parameters during the + // + // This depth is used for setting up a LambdaScopeInfo (at + // Sema::RecordParsingTemplateParameterDepth), which participates in the + // invented template parameters later at InventTemplateParameter. + // + // This way, abbreviated generic lambdas could have different template + // depths, avoiding substitution into wrong template parameters during the // satisfaction check. ++CurTemplateDepthTracker; ExprResult RequiresClause; diff --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp b/clang/test/Parser/cxx-concepts-requires-clause.cpp index f268092728fdfe..5b5bc9ea978bf2 100644 --- a/clang/test/Parser/cxx-concepts-requires-clause.cpp +++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp @@ -185,9 +185,9 @@ struct E {}; void F() { G([]<typename T> -// ~~~~~~~~~~ T: 0,0 +// ~~~~~~~~~~ T: Depth: 0, Index: 0 requires requires { [](auto...) {}; }(T) -// ~~~~ auto: 1,0 +// ~~~~ auto: Depth: 1, Index: 0 { return T(); }, E{}); } >From 654ca4e575caab40334c8f46f405ff8fa42036d7 Mon Sep 17 00:00:00 2001 From: Younan Zhang <zyn7...@gmail.com> Date: Thu, 22 Feb 2024 20:52:14 +0800 Subject: [PATCH 4/4] Address comments --- clang/docs/ReleaseNotes.rst | 8 ++++---- clang/lib/Parse/ParseExprCXX.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 32c161d5f18ee7..63a146879c02d5 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -243,10 +243,6 @@ Bug Fixes to C++ Support - Fixed an out-of-bounds error caused by building a recovery expression for ill-formed function calls while substituting into constraints. (`#58548 <https://github.com/llvm/llvm-project/issues/58548>`_) -- Fixed an issue where template parameters of the nested abbreviated generic lambda within - a requires-clause lie at the same depth as those of the surrounding lambda. This, - in turn, results in the wrong template argument substitution during the constraint checking. - (`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_) - Fix incorrect code generation caused by the object argument of ``static operator()`` and ``static operator[]`` calls not being evaluated. Fixes (`#67976 <https://github.com/llvm/llvm-project/issues/67976>`_) - Fix crash and diagnostic with const qualified member operator new. @@ -279,6 +275,10 @@ Bug Fixes to C++ Support (`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_) - Correctly immediate-escalate lambda conversion functions. (`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_) +- Fixed an issue where template parameters of a nested abbreviated generic lambda within + a requires-clause lie at the same depth as those of the surrounding lambda. This, + in turn, results in the wrong template argument substitution during constraint checking. + (`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 7ab38e59ac4bf8..22ee60af4616d2 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -1387,13 +1387,13 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( } else { // We increase the template depth before recursing into a requires-clause. // - // This depth is used for setting up a LambdaScopeInfo (at - // Sema::RecordParsingTemplateParameterDepth), which participates in the - // invented template parameters later at InventTemplateParameter. + // This depth is used for setting up a LambdaScopeInfo (in + // Sema::RecordParsingTemplateParameterDepth), which is used later when + // inventing template parameters in InventTemplateParameter. // // This way, abbreviated generic lambdas could have different template - // depths, avoiding substitution into wrong template parameters during the - // satisfaction check. + // depths, avoiding substitution into the wrong template parameters during + // constraint satisfaction check. ++CurTemplateDepthTracker; ExprResult RequiresClause; if (TryConsumeToken(tok::kw_requires)) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits