re PR c++/51229 ([C++0x] [4.7 Regression] Broken diagnostic: 'integer_cst' not suppor...
authorJakub Jelinek <jakub@redhat.com>
Wed, 7 Dec 2011 20:43:06 +0000 (21:43 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 7 Dec 2011 20:43:06 +0000 (21:43 +0100)
PR c++/51229
* decl.c (reshape_init_class): Complain if d->cur->index is
INTEGER_CST.
* parser.c (cp_parser_initializer_list): If cp_parser_parse_definitely
fails, clear designator.

* g++.dg/ext/desig3.C: New test.

From-SVN: r182088

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

index 76bd0af6162c0471713c12cf2c41de093d87d2d2..0224868d604de18e2e282cc27c45710bfdddad43 100644 (file)
@@ -1,5 +1,11 @@
 2011-12-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/51229
+       * decl.c (reshape_init_class): Complain if d->cur->index is
+       INTEGER_CST.
+       * parser.c (cp_parser_initializer_list): If cp_parser_parse_definitely
+       fails, clear designator.
+
        PR c++/51369
        * init.c (build_value_init): Allow array types even when
        processing_template_decl.
index 055c1b2020f014c51c6e88e57ffc2fc99de176ca..07cc9e65f5e4dbc43a02bf0ec63aae7ae652a77d 100644 (file)
@@ -5078,6 +5078,14 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
       /* Handle designated initializers, as an extension.  */
       if (d->cur->index)
        {
+         if (TREE_CODE (d->cur->index) == INTEGER_CST)
+           {
+             if (complain & tf_error)
+               error ("%<[%E] =%> used in a GNU-style designated initializer"
+                      " for class %qT", d->cur->index, type);
+             return error_mark_node;
+           }
+
          field = lookup_field_1 (type, d->cur->index, /*want_type=*/false);
 
          if (!field || TREE_CODE (field) != FIELD_DECL)
index 17a607d4f3d401a3a0af31872fb43532f818b852..5952a0f67f3fdca1528df2846f2407b3c36823c8 100644 (file)
@@ -17737,7 +17737,8 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p)
          designator = cp_parser_constant_expression (parser, false, NULL);
          cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
          cp_parser_require (parser, CPP_EQ, RT_EQ);
-         cp_parser_parse_definitely (parser);
+         if (!cp_parser_parse_definitely (parser))
+           designator = NULL_TREE;
        }
       else
        designator = NULL_TREE;
index 1a4a182a8f7695319c04bdddee49caddf7d3e3d5..9803f77e8052dc400652b2d2781f9a08c9cce3a0 100644 (file)
@@ -1,5 +1,8 @@
 2011-12-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/51229
+       * g++.dg/ext/desig3.C: New test.
+
        PR c++/51369
        * g++.dg/cpp0x/constexpr-51369.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/ext/desig3.C b/gcc/testsuite/g++.dg/ext/desig3.C
new file mode 100644 (file)
index 0000000..d1ff5e5
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/51229
+// { dg-do compile }
+// { dg-options "" }
+
+struct A { int i; };
+
+int a[5] = { .foo = 7 };// { dg-error "used in a GNU-style designated initializer for an array" }
+int b[] = { .foo = 8 };        // { dg-error "used in a GNU-style designated initializer for an array" }
+A c = { [0] = {} };    // { dg-error "used in a GNU-style designated initializer for class" }