From 2af5cb50138bbbf597b143740f42d4e9d1c37816 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 10 Jan 2017 14:04:22 -0500 Subject: [PATCH] FI 20, decomposition declaration with parenthesized initializer. * parser.c (cp_parser_decomposition_declaration): Use cp_parser_initializer. From-SVN: r244282 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 21 ++++++--------------- gcc/testsuite/g++.dg/cpp1z/decomp20.C | 10 ++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/decomp20.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5a84068e1df..25f5a85db92 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-01-10 Jason Merrill + + FI 20, decomposition declaration with parenthesized initializer. + * parser.c (cp_parser_decomposition_declaration): Use + cp_parser_initializer. + 2017-01-09 Jason Merrill Implement P0195R2, C++17 variadic using. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index aa045c439b3..45173131ee9 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -12923,7 +12923,7 @@ cp_parser_simple_declaration (cp_parser* parser, /* Helper of cp_parser_simple_declaration, parse a decomposition declaration. decl-specifier-seq ref-qualifier [opt] [ identifier-list ] - brace-or-equal-initializer ; */ + initializer ; */ static tree cp_parser_decomposition_declaration (cp_parser *parser, @@ -13022,21 +13022,12 @@ cp_parser_decomposition_declaration (cp_parser *parser, || cp_lexer_next_token_is_not (parser->lexer, CPP_COLON)) { bool non_constant_p = false, is_direct_init = false; - tree initializer; *init_loc = cp_lexer_peek_token (parser->lexer)->location; - /* Parse the initializer. */ - if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) - { - initializer = cp_parser_braced_list (parser, &non_constant_p); - CONSTRUCTOR_IS_DIRECT_INIT (initializer) = 1; - is_direct_init = true; - } - else - { - /* Consume the `='. */ - cp_parser_require (parser, CPP_EQ, RT_EQ); - initializer = cp_parser_initializer_clause (parser, &non_constant_p); - } + tree initializer = cp_parser_initializer (parser, &is_direct_init, + &non_constant_p); + if (TREE_CODE (initializer) == TREE_LIST) + initializer = build_x_compound_expr_from_list (initializer, ELK_INIT, + tf_warning_or_error); if (decl != error_mark_node) { diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp20.C b/gcc/testsuite/g++.dg/cpp1z/decomp20.C new file mode 100644 index 00000000000..8831b7186c0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp20.C @@ -0,0 +1,10 @@ +// { dg-options -std=c++1z } + +struct A { int i,j; }; + +A f(); + +int main() +{ + auto [i,j] (f()); +} -- 2.30.2