re PR c++/10207 (Empty structure initialization fails under C++ (but works under C))
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 20 May 2013 09:41:42 +0000 (09:41 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 20 May 2013 09:41:42 +0000 (09:41 +0000)
/cp
2013-05-20  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/10207
* parser.c (cp_parser_postfix_expression): Use cp_parser_braced_list
instead of cp_parser_initializer_list for compound-literals.

/testsuite
2013-05-20  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/10207
* g++.dg/ext/complit13.C: New.

From-SVN: r199096

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

index 73b8deb..dd53e69 100644 (file)
@@ -1,3 +1,9 @@
+2013-05-20  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/10207
+       * parser.c (cp_parser_postfix_expression): Use cp_parser_braced_list
+       instead of cp_parser_initializer_list for compound-literals.
+
 2013-05-20  Marc Glisse  <marc.glisse@inria.fr>
 
        PR c++/57175
index 022886e..91e6615 100644 (file)
@@ -5719,7 +5719,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
        if (cp_parser_allow_gnu_extensions_p (parser)
            && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
          {
-           vec<constructor_elt, va_gc> *initializer_list = NULL;
+           tree initializer = NULL_TREE;
            bool saved_in_type_id_in_expr_p;
 
            cp_parser_parse_tentatively (parser);
@@ -5732,21 +5732,19 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
            parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
            /* Look for the `)'.  */
            cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
-           /* Look for the `{'.  */
-           cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE);
            /* If things aren't going well, there's no need to
               keep going.  */
            if (!cp_parser_error_occurred (parser))
              {
-               bool non_constant_p;
-               /* Parse the initializer-list.  */
-               initializer_list
-                 = cp_parser_initializer_list (parser, &non_constant_p);
-               /* Allow a trailing `,'.  */
-               if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
-                 cp_lexer_consume_token (parser->lexer);
-               /* Look for the final `}'.  */
-               cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+               if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
+                 {
+                   bool non_constant_p;
+                   /* Parse the brace-enclosed initializer list.  */
+                   initializer = cp_parser_braced_list (parser,
+                                                        &non_constant_p);
+                 }
+               else
+                 cp_parser_simulate_error (parser);
              }
            /* If that worked, we're definitely looking at a
               compound-literal expression.  */
@@ -5754,7 +5752,8 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
              {
                /* Warn the user that a compound literal is not
                   allowed in standard C++.  */
-               pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids compound-literals");
+               pedwarn (input_location, OPT_Wpedantic,
+                        "ISO C++ forbids compound-literals");
                /* For simplicity, we disallow compound literals in
                   constant-expressions.  We could
                   allow compound literals of integer type, whose
@@ -5772,10 +5771,8 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
                  }
                /* Form the representation of the compound-literal.  */
                postfix_expression
-                 = (finish_compound_literal
-                    (type, build_constructor (init_list_type_node,
-                                              initializer_list),
-                     tf_warning_or_error));
+                 = finish_compound_literal (type, initializer,
+                                            tf_warning_or_error);
                break;
              }
          }
index 5a113d7..dfde009 100644 (file)
@@ -1,3 +1,8 @@
+2013-05-20  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/10207
+       * g++.dg/ext/complit13.C: New.
+
 2013-05-20  Marc Glisse  <marc.glisse@inria.fr>
 
        PR c++/57175
diff --git a/gcc/testsuite/g++.dg/ext/complit13.C b/gcc/testsuite/g++.dg/ext/complit13.C
new file mode 100644 (file)
index 0000000..c12678b
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/10207
+// { dg-options "" }
+
+typedef struct { } EmptyStruct;
+typedef struct { EmptyStruct Empty; } DemoStruct;
+
+void Func()
+{
+  DemoStruct Demo;
+  Demo.Empty = (EmptyStruct) {};
+}