On 11/15/24 9:08 AM, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
The error here should also check that we aren't nested in another
lambda; in it, at_function_scope_p() will be false.

        PR c++/117602

gcc/cp/ChangeLog:

        * parser.cc (cp_parser_lambda_introducer): Check if we're in a lambda
        before emitting the error about a non-local lambda with
        a capture-default.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp2a/lambda-uneval19.C: New test.
---
  gcc/cp/parser.cc                             |  5 ++++-
  gcc/testsuite/g++.dg/cpp2a/lambda-uneval19.C | 14 ++++++++++++++
  2 files changed, 18 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-uneval19.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 07b12224615..dc79ff42a3b 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -11611,7 +11611,10 @@ cp_parser_lambda_introducer (cp_parser* parser, tree 
lambda_expr)
        cp_lexer_consume_token (parser->lexer);
        first = false;
- if (!(at_function_scope_p () || parsing_nsdmi ()))
+      if (!(at_function_scope_p ()
+           || parsing_nsdmi ()
+           || (current_class_type
+               && LAMBDA_TYPE_P (current_class_type))))

How about using current_nonlambda_scope () instead of at_function_scope_p ()?

Jason

Reply via email to