Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

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.
---
 gcc/cp/parser.cc                           | 3 +++
 gcc/testsuite/g++.dg/cpp2a/lambda-targ17.C | 8 ++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-targ17.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 968c0f50d16..d96fdf8f927 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 00000000000..84955aede3e
--- /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) {}>;
+}

base-commit: 131ba6137bca263d7381ad3331840ee05e306fc9
-- 
2.49.0

Reply via email to