From 82a926bf06e8b7989ee189ef2b3bf7a6c055d6b8 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 2 Apr 2018 14:20:04 -0400 Subject: [PATCH] PR c++/64095 - auto... parameter pack. * parser.c (cp_parser_parameter_declaration): Handle turning autos into packs here. (cp_parser_parameter_declaration_list): Not here. From-SVN: r259015 --- gcc/cp/ChangeLog | 7 ++++ gcc/cp/parser.c | 40 ++++++++++--------- .../g++.dg/cpp1y/lambda-generic-variadic16.C | 8 ++++ gcc/testsuite/g++.dg/cpp1y/lambda-mangle-1.C | 2 +- 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic16.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d52a0dc33a3..e97442a5bea 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-04-02 Jason Merrill + + PR c++/64095 - auto... parameter pack. + * parser.c (cp_parser_parameter_declaration): Handle turning autos + into packs here. + (cp_parser_parameter_declaration_list): Not here. + 2018-03-31 Alexandre Oliva PR c++/85027 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index e946d0b7229..d526a4eb365 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -21320,9 +21320,6 @@ cp_parser_parameter_declaration_list (cp_parser* parser, bool *is_error) cp_parameter_declarator *parameter; tree decl = error_mark_node; bool parenthesized_p = false; - int template_parm_idx = (function_being_declared_is_template_p (parser)? - TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS - (current_template_parms)) : 0); /* Parse the parameter. */ parameter @@ -21336,22 +21333,6 @@ cp_parser_parameter_declaration_list (cp_parser* parser, bool *is_error) if (parameter) { - /* If a function parameter pack was specified and an implicit template - parameter was introduced during cp_parser_parameter_declaration, - change any implicit parameters introduced into packs. */ - if (parser->implicit_template_parms - && parameter->declarator - && parameter->declarator->parameter_pack_p) - { - int latest_template_parm_idx = TREE_VEC_LENGTH - (INNERMOST_TEMPLATE_PARMS (current_template_parms)); - - if (latest_template_parm_idx != template_parm_idx) - parameter->decl_specifiers.type = convert_generic_types_to_packs - (parameter->decl_specifiers.type, - template_parm_idx, latest_template_parm_idx); - } - decl = grokdeclarator (parameter->declarator, ¶meter->decl_specifiers, PARM, @@ -21511,6 +21492,10 @@ cp_parser_parameter_declaration (cp_parser *parser, parser->type_definition_forbidden_message = G_("types may not be defined in parameter types"); + int template_parm_idx = (function_being_declared_is_template_p (parser) ? + TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS + (current_template_parms)) : 0); + /* Parse the declaration-specifiers. */ cp_token *decl_spec_token_start = cp_lexer_peek_token (parser->lexer); cp_parser_decl_specifier_seq (parser, @@ -21600,6 +21585,23 @@ cp_parser_parameter_declaration (cp_parser *parser, parameter pack expansion expression. Otherwise, leave the ellipsis for a C-style variadic function. */ token = cp_lexer_peek_token (parser->lexer); + + /* If a function parameter pack was specified and an implicit template + parameter was introduced during cp_parser_parameter_declaration, + change any implicit parameters introduced into packs. */ + if (parser->implicit_template_parms + && (token->type == CPP_ELLIPSIS + || (declarator && declarator->parameter_pack_p))) + { + int latest_template_parm_idx = TREE_VEC_LENGTH + (INNERMOST_TEMPLATE_PARMS (current_template_parms)); + + if (latest_template_parm_idx != template_parm_idx) + decl_specifiers.type = convert_generic_types_to_packs + (decl_specifiers.type, + template_parm_idx, latest_template_parm_idx); + } + if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)) { tree type = decl_specifiers.type; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic16.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic16.C new file mode 100644 index 00000000000..a9292253453 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic16.C @@ -0,0 +1,8 @@ +// PR c++/64095 +// { dg-do compile { target c++14 } } + +void f() +{ + [](auto...){}(); + [](auto&&...){}(); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-mangle-1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-mangle-1.C index ca0910be503..8f135358465 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-mangle-1.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-mangle-1.C @@ -85,4 +85,4 @@ void Baz () // { dg-final { scan-assembler "_Z3eatIZ3FoovEUlPT_PT0_E4_Z3FoovEUlS1_S3_E5_EvRS0_RS2_:" } } // { dg-final { scan-assembler "_Z3eatIPiZ3BarIsEvvEUlPsPfS3_E_EvRT_RT0_:" } } // { dg-final { scan-assembler "_Z3eatIPiZ3BarIsEvvEUlPsPT_PT0_E0_EvRS3_RS5_:" } } -// { dg-final { scan-assembler "_Z3eatIPiZ3BarIsEvvEUlPsPT_zE1_EvRS3_RT0_:" } } +// { dg-final { scan-assembler "_Z3eatIPiZ3BarIsEvvEUlPsDpPT_E1_EvRT_RT0_:" } } -- 2.30.2