]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix ICE with lambdas combining explicit and implicit template params [PR117518] master trunk
authorEgas Ribeiro <egas.g.ribeiro@gmail.com>
Fri, 19 Dec 2025 16:58:58 +0000 (16:58 +0000)
committerJason Merrill <jason@redhat.com>
Tue, 23 Dec 2025 08:30:09 +0000 (15:30 +0700)
When a lambda with explicit template parameters like []<int> also has
implicit template parameters from auto, and is used as a default
template argument, processing_template_parmlist remained set
from the outer template context. This caused
function_being_declared_is_template_p to incorrectly return false,
leading synthesize_implicit_template_parm to create a new template
scope instead of extending the existing one, resulting in a binding
level mismatch and an ICE in poplevel_class.

Fix by clearing processing_template_parmlist in
cp_parser_lambda_expression alongside the other parser state
save/restore operations.

PR c++/117518

gcc/cp/ChangeLog:

* parser.cc (cp_parser_lambda_expression): Clear
processing_template_parmlist when parsing lambda body.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-targ19.C: New test.

Signed-off-by: Egas Ribeiro <egas.g.ribeiro@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp2a/lambda-targ19.C [new file with mode: 0644]

index b3bf0703d3d2385b3f06fc44c218fb8847a83e7f..26da789f821878a0110df84eaea0046280cc77f9 100644 (file)
@@ -12043,6 +12043,8 @@ cp_parser_lambda_expression (cp_parser* parser,
     bool saved_omp_array_section_p = parser->omp_array_section_p;
     bool saved_in_targ = parser->in_template_argument_list_p;
     bool saved_in_declarator_p = parser->in_declarator_p;
+    auto parmlist_sentinel
+      = make_temp_override (processing_template_parmlist, 0);
 
     parser->num_template_parameter_lists = 0;
     parser->in_statement = 0;
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ19.C b/gcc/testsuite/g++.dg/cpp2a/lambda-targ19.C
new file mode 100644 (file)
index 0000000..d02f6d6
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do compile { target c++20 } }
+// PR c++/117518
+template <auto = []<int> (auto) {}> int x;
+int y = x<>;