https://gcc.gnu.org/g:d1c92ea10d30e4cf359faa8bbe3782ed6173d8a9

commit r16-2148-gd1c92ea10d30e4cf359faa8bbe3782ed6173d8a9
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed Jul 9 11:03:31 2025 -0400

    c++: generic lambda in template arg [PR121012]
    
    My r16-2065 adding missed errors for auto in a template arg in a lambda
    parameter also introduced a bogus error on this testcase, where the auto is
    both in a lambda parameter and in a template arg, but in the other order,
    which is OK.  So we should clear in_template_argument_list_p for lambdas
    like we do so many other parser flags.
    
            PR c++/121012
            PR c++/120917
    
    gcc/cp/ChangeLog:
    
            * parser.cc (cp_parser_lambda_expression): Clear
            parser->in_template_argument_list_p.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/lambda-targ17.C: New test.

Diff:
---
 gcc/cp/parser.cc                           | 3 +++
 gcc/testsuite/g++.dg/cpp2a/lambda-targ17.C | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 968c0f50d162..d96fdf8f9271 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -11838,6 +11838,7 @@ cp_parser_lambda_expression (cp_parser* parser)
     bool auto_is_implicit_function_template_parm_p
         = parser->auto_is_implicit_function_template_parm_p;
     bool saved_omp_array_section_p = parser->omp_array_section_p;
+    bool saved_in_targ = parser->in_template_argument_list_p;
 
     parser->num_template_parameter_lists = 0;
     parser->in_statement = 0;
@@ -11847,6 +11848,7 @@ cp_parser_lambda_expression (cp_parser* parser)
     parser->implicit_template_scope = 0;
     parser->auto_is_implicit_function_template_parm_p = false;
     parser->omp_array_section_p = false;
+    parser->in_template_argument_list_p = false;
 
     /* Inside the lambda, outside unevaluated context do not apply.  */
     cp_evaluated ev;
@@ -11901,6 +11903,7 @@ cp_parser_lambda_expression (cp_parser* parser)
     parser->auto_is_implicit_function_template_parm_p
        = auto_is_implicit_function_template_parm_p;
     parser->omp_array_section_p = saved_omp_array_section_p;
+    parser->in_template_argument_list_p = saved_in_targ;
   }
 
   /* This lambda shouldn't have any proxies left at this point.  */
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ17.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-targ17.C
new file mode 100644
index 000000000000..84955aede3e8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ17.C
@@ -0,0 +1,8 @@
+// PR c++/12012
+// { dg-do compile { target c++20 } }
+
+template<auto> int x;
+
+int main() {
+       x<[](auto) {}>;
+}

Reply via email to