]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: generic lambda in template arg [PR121012]
authorJason Merrill <jason@redhat.com>
Wed, 9 Jul 2025 15:03:31 +0000 (11:03 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 9 Jul 2025 15:49:36 +0000 (11:49 -0400)
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
gcc/testsuite/g++.dg/cpp2a/lambda-targ17.C [new file with mode: 0644]

index 968c0f50d1626b4b53e33a0626fcabf10456ad2c..d96fdf8f9271b1fc3597e89aa3f069b203e43b85 100644 (file)
@@ -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 (file)
index 0000000..84955ae
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/12012
+// { dg-do compile { target c++20 } }
+
+template<auto> int x;
+
+int main() {
+       x<[](auto) {}>;
+}