diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3dfb31ad4b4..01044e493d7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-03-26 Paolo Carlini + + PR c++/55951 + * decl.c (check_array_designated_initializer): Handle CONST_DECL + as ce->index. + 2013-03-26 Paolo Carlini * decl.c (grokfndecl): Handle separately and diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a8213288215..ca68bb509bf 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4760,7 +4760,7 @@ grok_reference_init (tree decl, tree type, tree init, int flags) is valid, i.e., does not have a designated initializer. */ static bool -check_array_designated_initializer (const constructor_elt *ce, +check_array_designated_initializer (constructor_elt *ce, unsigned HOST_WIDE_INT index) { /* Designated initializers for array elements are not supported. */ @@ -4769,9 +4769,21 @@ check_array_designated_initializer (const constructor_elt *ce, /* The parser only allows identifiers as designated initializers. */ if (ce->index == error_mark_node) - error ("name used in a GNU-style designated " - "initializer for an array"); - else if (TREE_CODE (ce->index) == INTEGER_CST) + { + error ("name used in a GNU-style designated " + "initializer for an array"); + return false; + } + else if (identifier_p (ce->index)) + { + error ("name %qD used in a GNU-style designated " + "initializer for an array", ce->index); + return false; + } + + ce->index = cxx_constant_value (ce->index); + + if (TREE_CODE (ce->index) == INTEGER_CST) { /* A C99 designator is OK if it matches the current index. */ if (TREE_INT_CST_LOW (ce->index) == index) @@ -4780,11 +4792,8 @@ check_array_designated_initializer (const constructor_elt *ce, sorry ("non-trivial designated initializers not supported"); } else - { - gcc_assert (identifier_p (ce->index)); - error ("name %qD used in a GNU-style designated " - "initializer for an array", ce->index); - } + gcc_unreachable (); + return false; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c1117941e63..1f53a31a8f2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-03-26 Paolo Carlini + + PR c++/55951 + * g++.dg/ext/desig5.C: New. + 2013-03-26 Tobias Burnus PR fortran/56649 diff --git a/gcc/testsuite/g++.dg/ext/desig5.C b/gcc/testsuite/g++.dg/ext/desig5.C new file mode 100644 index 00000000000..48cce3183b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/desig5.C @@ -0,0 +1,7 @@ +// PR c++/55951 + +enum { A }; + +static const char *a[] = { + [A] = "a" +};