re PR c++/55951 (ICE in check_array_designated_initializer, at cp/decl.c:4785)

/cp
2013-03-26  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/55951
	* decl.c (check_array_designated_initializer): Handle CONST_DECL
	as ce->index.

/testsuite
2013-03-26  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/55951
	* g++.dg/ext/desig5.C: New.

From-SVN: r197116
This commit is contained in:
Paolo Carlini 2013-03-26 16:49:49 +00:00 committed by Paolo Carlini
parent 6f33817e6a
commit 515e4d1d5a
4 changed files with 36 additions and 9 deletions

View File

@ -1,3 +1,9 @@
2013-03-26 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/55951
* decl.c (check_array_designated_initializer): Handle CONST_DECL
as ce->index.
2013-03-26 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (grokfndecl): Handle separately <inline> and <constexpr>

View File

@ -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;
}

View File

@ -1,3 +1,8 @@
2013-03-26 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/55951
* g++.dg/ext/desig5.C: New.
2013-03-26 Tobias Burnus <burnus@net-b.de>
PR fortran/56649

View File

@ -0,0 +1,7 @@
// PR c++/55951
enum { A };
static const char *a[] = {
[A] = "a"
};