[backport from gcc-4.8/trunk r190962 ] gcc/cp/ 2012-09-04 Jason Merrill PR c++/54441 * decl.c (reshape_init_class): Handle invalid initializer for 0-length array member. * error.c (dump_type_suffix): Correct handling of 0-length arrays. gcc/testsuite/ 2012-09-04 Jason Merrill PR c++/54441 * g++.dg/ext/flexary3.C: New. --- gcc-4.7.1/gcc/cp/decl.c.~1~ 2012-05-10 23:06:42.000000000 +0200 +++ gcc-4.7.1/gcc/cp/decl.c 2012-09-08 20:58:59.000000000 +0200 @@ -5097,6 +5097,7 @@ reshape_init_class (tree type, reshape_i while (d->cur != d->end) { tree field_init; + constructor_elt *old_cur = d->cur; /* Handle designated initializers, as an extension. */ if (d->cur->index) @@ -5129,6 +5130,15 @@ reshape_init_class (tree type, reshape_i if (field_init == error_mark_node) return error_mark_node; + if (d->cur->index && d->cur == old_cur) + { + /* This can happen with an invalid initializer for a flexible + array member (c++/54441). */ + if (complain & tf_error) + error ("invalid initializer for %q#D", field); + return error_mark_node; + } + CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init); /* [dcl.init.aggr] --- gcc-4.7.1/gcc/cp/error.c.~1~ 2012-02-16 20:42:08.000000000 +0100 +++ gcc-4.7.1/gcc/cp/error.c 2012-09-08 20:58:59.000000000 +0200 @@ -846,7 +846,9 @@ dump_type_suffix (tree t, int flags) { tree dtype = TYPE_DOMAIN (t); tree max = TYPE_MAX_VALUE (dtype); - if (host_integerp (max, 0)) + if (integer_all_onesp (max)) + pp_character (cxx_pp, '0'); + else if (host_integerp (max, 0)) pp_wide_integer (cxx_pp, tree_low_cst (max, 0) + 1); else if (TREE_CODE (max) == MINUS_EXPR) dump_expr (TREE_OPERAND (max, 0), --- gcc-4.7.1/gcc/testsuite/g++.dg/ext/flexary3.C.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.7.1/gcc/testsuite/g++.dg/ext/flexary3.C 2012-09-08 20:58:59.000000000 +0200 @@ -0,0 +1,10 @@ +// PR c++/54441 +// { dg-options "" } + +struct s { char c[]; }; + +int main() +{ + struct s s = { .c = 0 }; // { dg-error "initializer" } + return 0; +}