The code in reshape_init_class shouldn't assume that anything not an
INTEGER_CST or FIELD_DECL is an IDENTIFIER_NODE.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 6a71aad5b83d18f742ee208dd249c7759e5cccb3
Author: Jason Merrill <ja...@redhat.com>
Date: Mon Jun 2 21:51:08 2014 -0400
PR c++/61046
* decl.c (reshape_init_class): Handle un-folded
constant-expressions.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c61ad68..8dc5f1f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5294,19 +5294,18 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
if (d->cur->index == error_mark_node)
return error_mark_node;
- 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;
- }
-
if (TREE_CODE (d->cur->index) == FIELD_DECL)
/* We already reshaped this. */
gcc_assert (d->cur->index == field);
- else
+ else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
field = lookup_field_1 (type, d->cur->index, /*want_type=*/false);
+ else
+ {
+ if (complain & tf_error)
+ error ("%<[%E] =%> used in a GNU-style designated initializer"
+ " for class %qT", d->cur->index, type);
+ return error_mark_node;
+ }
if (!field || TREE_CODE (field) != FIELD_DECL)
{
diff --git a/gcc/testsuite/g++.dg/ext/desig7.C b/gcc/testsuite/g++.dg/ext/desig7.C
new file mode 100644
index 0000000..44358ec
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/desig7.C
@@ -0,0 +1,8 @@
+// PR c++/61046
+
+struct A
+{
+ int ary[4];
+};
+const int i = 0;
+A bar = { [i] = 0 }; // { dg-error "designated" }