C++ PATCH for C++17 NB comment FI20 (parenthesized initialization with decomposition)

Jason Merrill jason@redhat.com
Tue Jan 10 19:03:00 GMT 2017


The FI20 comment on the decomposition declarations proposal complained
that the syntax unnecessarily excluded parenthesized initialization.
This patch implements the resolution.

Tested x86_64-pc-linux-gnu, applying to trunk.
-------------- next part --------------
commit 749ec367e50b356a40fd41a3daae10d9d948062b
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jan 9 17:33:42 2017 -0500

            FI 20, decomposition declaration with parenthesized initializer.
    
            * parser.c (cp_parser_decomposition_declaration): Use
            cp_parser_initializer.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index aa045c4..4517313 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 0000000..8831b71
--- /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());
+}


More information about the Gcc-patches mailing list