FI 20, decomposition declaration with parenthesized initializer.
authorJason Merrill <jason@redhat.com>
Tue, 10 Jan 2017 19:04:22 +0000 (14:04 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 10 Jan 2017 19:04:22 +0000 (14:04 -0500)
* parser.c (cp_parser_decomposition_declaration): Use
cp_parser_initializer.

From-SVN: r244282

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp1z/decomp20.C [new file with mode: 0644]

index 5a84068e1dfacb45755f797b224c7a79b32d881c..25f5a85db92e68847128b8816cf0752fcf17406b 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-10  Jason Merrill  <jason@redhat.com>
+
+       FI 20, decomposition declaration with parenthesized initializer.
+       * parser.c (cp_parser_decomposition_declaration): Use
+       cp_parser_initializer.
+
 2017-01-09  Jason Merrill  <jason@redhat.com>
 
        Implement P0195R2, C++17 variadic using.
index aa045c439b336e31e0594f38fe6334f24afe0ecf..45173131ee93045ecbdeaf41f16329b63dae0a79 100644 (file)
@@ -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 (file)
index 0000000..8831b71
--- /dev/null
@@ -0,0 +1,10 @@
+// { dg-options -std=c++1z }
+
+struct A { int i,j; };
+
+A f();
+
+int main()
+{
+  auto [i,j] (f());
+}