Commit 6f8e335e by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/51229 ([C++0x] [4.7 Regression] Broken diagnostic: 'integer_cst' not…

re PR c++/51229 ([C++0x] [4.7 Regression] Broken diagnostic: 'integer_cst' not supported by dump_dec)

	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
parent 14b1860e
2011-12-07 Jakub Jelinek <jakub@redhat.com> 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 PR c++/51369
* init.c (build_value_init): Allow array types even when * init.c (build_value_init): Allow array types even when
processing_template_decl. processing_template_decl.
......
...@@ -5078,6 +5078,14 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p, ...@@ -5078,6 +5078,14 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
/* Handle designated initializers, as an extension. */ /* Handle designated initializers, as an extension. */
if (d->cur->index) 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); field = lookup_field_1 (type, d->cur->index, /*want_type=*/false);
if (!field || TREE_CODE (field) != FIELD_DECL) if (!field || TREE_CODE (field) != FIELD_DECL)
......
...@@ -17737,7 +17737,8 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p) ...@@ -17737,7 +17737,8 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p)
designator = cp_parser_constant_expression (parser, false, NULL); designator = cp_parser_constant_expression (parser, false, NULL);
cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE); cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
cp_parser_require (parser, CPP_EQ, RT_EQ); cp_parser_require (parser, CPP_EQ, RT_EQ);
cp_parser_parse_definitely (parser); if (!cp_parser_parse_definitely (parser))
designator = NULL_TREE;
} }
else else
designator = NULL_TREE; designator = NULL_TREE;
......
2011-12-07 Jakub Jelinek <jakub@redhat.com> 2011-12-07 Jakub Jelinek <jakub@redhat.com>
PR c++/51229
* g++.dg/ext/desig3.C: New test.
PR c++/51369 PR c++/51369
* g++.dg/cpp0x/constexpr-51369.C: New test. * g++.dg/cpp0x/constexpr-51369.C: New test.
......
// 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" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment