PR c++/60052 * parser.c (cp_parser_parameter_declaration_list): Correctly reset implicit_template_scope upon leaving an out-of-line generic member function definition.
PR c++/60052 * g++.dg/cpp1y/pr60052.C: New testcase. --- gcc/cp/parser.c | 16 +++++++++++++--- gcc/testsuite/g++.dg/cpp1y/pr60052.C | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr60052.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 9818213..68573f1 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -18372,11 +18372,21 @@ cp_parser_parameter_declaration_list (cp_parser* parser, bool *is_error) parser->in_unbraced_linkage_specification_p = saved_in_unbraced_linkage_specification_p; + /* Reset implicit_template_scope if we are about to leave the function + parameter list that introduced it. Note that for out-of-line member + definitions, there will be one or more class scopes before we get to + the template parameter scope. */ + if (cp_binding_level *its = parser->implicit_template_scope) - if (current_binding_level->level_chain == its) + if (cp_binding_level *maybe_its = current_binding_level->level_chain) { - parser->implicit_template_parms = 0; - parser->implicit_template_scope = 0; + while (maybe_its->kind == sk_class) + maybe_its = maybe_its->level_chain; + if (maybe_its == its) + { + parser->implicit_template_parms = 0; + parser->implicit_template_scope = 0; + } } return parameters; diff --git a/gcc/testsuite/g++.dg/cpp1y/pr60052.C b/gcc/testsuite/g++.dg/cpp1y/pr60052.C new file mode 100644 index 0000000..191e5ac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr60052.C @@ -0,0 +1,15 @@ +// PR c++/60052 +// { dg-do compile } +// { dg-options "-std=c++1y" } + +struct A +{ + void foo(auto); +}; + +void A::foo(auto) {} + +struct B +{ + void bar(auto); +}; -- 1.8.5.5