Bootstrapped and regtested on x86_64-pc-linux-gnu.
-- >8 --
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 this by temporarily clearing processing_template_parmlist when
parsing lambda parameters.
PR c++/117518
gcc/cp/ChangeLog:
* parser.cc (cp_parser_lambda_declarator_opt): Clear
processing_template_parmlist when parsing lambda parameters.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/lambda-default-template-117518.C: New test.
Signed-off-by: Egas Ribeiro <[email protected]>
---
gcc/cp/parser.cc | 2 ++
gcc/testsuite/g++.dg/cpp1z/lambda-default-template-117518.C | 3 +++
2 files changed, 5 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp1z/lambda-default-template-117518.C
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index cdfa8f0122d..3dc3263f59d 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -12550,6 +12550,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser,
tree lambda_expr,
begin_scope (sk_function_parms, /*entity=*/NULL_TREE);
/* Parse parameters. */
+ auto parmlist_sentinel
+ = make_temp_override (processing_template_parmlist, 0);
param_list
= cp_parser_parameter_declaration_clause
(parser, CP_PARSER_FLAGS_TYPENAME_OPTIONAL, /*lambda_p=*/true);
diff --git a/gcc/testsuite/g++.dg/cpp1z/lambda-default-template-117518.C
b/gcc/testsuite/g++.dg/cpp1z/lambda-default-template-117518.C
new file mode 100644
index 00000000000..55318943acf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/lambda-default-template-117518.C
@@ -0,0 +1,3 @@
+// { dg-do compile { target c++20 } }
+// PR c++/117518
+template <auto = []<int> (auto) {}> int x;
--
2.52.0