* cp/parser.c (cp_parser_template_parameter): Early out with error_mark_node if parameter declaration was not parsed.
* g++.dg/cpp1y/pr59636.C: New testcase. --- gcc/cp/parser.c | 12 ++++++------ gcc/testsuite/g++.dg/cpp1y/pr59636.C | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr59636.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 35dcefd..4f737df 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -12981,20 +12981,21 @@ cp_parser_template_parameter (cp_parser* parser, bool *is_non_type, = cp_parser_parameter_declaration (parser, /*template_parm_p=*/true, /*parenthesized_p=*/NULL); + if (!parameter_declarator) + return error_mark_node; + /* If the parameter declaration is marked as a parameter pack, set *IS_PARAMETER_PACK to notify the caller. Also, unmark the declarator's PACK_EXPANSION_P, otherwise we'll get errors from grokdeclarator. */ - if (parameter_declarator - && parameter_declarator->declarator + if (parameter_declarator->declarator && parameter_declarator->declarator->parameter_pack_p) { *is_parameter_pack = true; parameter_declarator->declarator->parameter_pack_p = false; } - if (parameter_declarator - && parameter_declarator->default_argument) + if (parameter_declarator->default_argument) { /* Can happen in some cases of erroneous input (c++/34892). */ if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)) @@ -13018,8 +13019,7 @@ cp_parser_template_parameter (cp_parser* parser, bool *is_non_type, /* We might end up with a pack expansion as the type of the non-type template parameter, in which case this is a non-type template parameter pack. */ - else if (parameter_declarator - && parameter_declarator->decl_specifiers.type + else if (parameter_declarator->decl_specifiers.type && PACK_EXPANSION_P (parameter_declarator->decl_specifiers.type)) { *is_parameter_pack = true; diff --git a/gcc/testsuite/g++.dg/cpp1y/pr59636.C b/gcc/testsuite/g++.dg/cpp1y/pr59636.C new file mode 100644 index 0000000..f2ca5b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr59636.C @@ -0,0 +1,7 @@ +// { dg-do compile } +// { dg-options "-std=c++1y" } + +// PR c++/59636 + +auto f = []() { return []<>() {}; }; // { dg-error "expected identifier" } + -- 1.8.5.2