gcc/c/ 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.8.0/gcc/c/c-typeck.c.~1~ 2013-01-24 17:59:44.000000000 +0100 +++ gcc-4.8.0/gcc/c/c-typeck.c 2013-05-12 16:46:28.795248735 +0200 @@ -6009,6 +6009,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, @@ -6062,8 +6065,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_Wpedantic, - "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_Wpedantic, + "initialization of a flexible array member"); + } if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), TYPE_MAIN_VARIANT (type))) @@ -6378,9 +6386,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) {...}. */