gcc/ 2013-05-12 Mikael Pettersson PR wrong-code/57180 * c-typeck.c (digest_init): If a flexible array member has a string literal initializer, issue an error if constructor_depth > 1. (constructor_depth): Move declaration above digest_init. --- gcc-4.7.3/gcc/c-typeck.c.~1~ 2012-09-20 22:50:17.000000000 +0200 +++ gcc-4.7.3/gcc/c-typeck.c 2013-05-12 18:12:40.334725693 +0200 @@ -6106,6 +6106,9 @@ maybe_warn_string_init (tree type, struc REQUIRE_CONSTANT requests an error if non-constant initializers or elements are seen. */ +/* The SPELLING_DEPTH of this constructor. */ +static int constructor_depth; + static tree digest_init (location_t init_loc, tree type, tree init, tree origtype, bool null_pointer_constant, bool strict_string, @@ -6159,8 +6162,13 @@ digest_init (location_t init_loc, tree t maybe_warn_string_init (type, expr); if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type))) - pedwarn_init (init_loc, OPT_pedantic, - "initialization of a flexible array member"); + { + if (constructor_depth > 1) + error_init ("initialization of flexible array member in a nested context"); + else + pedwarn_init (init_loc, OPT_pedantic, + "initialization of a flexible array member"); + } if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), TYPE_MAIN_VARIANT (type))) @@ -6475,9 +6483,6 @@ struct init_node Will never hold tree nodes across GC runs. */ static struct init_node *constructor_pending_elts; -/* The SPELLING_DEPTH of this constructor. */ -static int constructor_depth; - /* DECL node for which an initializer is being read. 0 means we are reading a constructor expression such as (struct foo) {...}. */