+2002-03-21 Eric Botcazou <ebotcazou@multimania.com>
+
+ PR c/5597
+ * c-typeck.c (process_init_element): Flag non-static
+ initialization of a flexible array member as illegal.
+
2002-03-22 Alan Modra <amodra@bigpond.net.au>
* config/rs6000/t-linux64: New.
2002-03-21 Aldy Hernandez <aldyh@redhat.com>
- * langhooks.c (lhd_tree_inlining_cannot_inline_tree_fn): Check
- flag_really_no_inline instead of optimize == 0.
+ * langhooks.c (lhd_tree_inlining_cannot_inline_tree_fn): Check
+ flag_really_no_inline instead of optimize == 0.
- * c-objc-common.c (c_cannot_inline_tree_fn): Same.
+ * c-objc-common.c (c_cannot_inline_tree_fn): Same.
- * cp/tree.c (cp_cannot_inline_tree_fn): Same.
+ * cp/tree.c (cp_cannot_inline_tree_fn): Same.
- * flags.h (flag_really_no_inline): New.
+ * flags.h (flag_really_no_inline): New.
- * c-common.c (c_common_post_options): Initialzie
- flag_really_no_inline.
+ * c-common.c (c_common_post_options): Initialzie
+ flag_really_no_inline.
- * toplev.c (flag_really_no_inline): New.
+ * toplev.c (flag_really_no_inline): New.
2002-03-21 Jakub Jelinek <jakub@redhat.com>
fieldtype = TYPE_MAIN_VARIANT (fieldtype);
fieldcode = TREE_CODE (fieldtype);
+ /* Error for non-static initialization of a flexible array member. */
+ if (fieldcode == ARRAY_TYPE
+ && !require_constant_value
+ && TYPE_SIZE (fieldtype) == NULL_TREE
+ && TREE_CHAIN (constructor_fields) == NULL_TREE)
+ {
+ error_init ("non-static initialization of a flexible array member");
+ break;
+ }
+
/* Accept a string constant to initialize a subarray. */
if (value != 0
&& fieldcode == ARRAY_TYPE
--- /dev/null
+/* PR c/5597 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+/* Verify that GCC forbids non-static initialization of
+ flexible array members. */
+
+struct str { int len; char s[]; };
+
+struct str a = { 2, "a" };
+
+void foo()
+{
+ static struct str b = { 2, "b" };
+ struct str c = { 2, "c" }; /* { dg-error "(non-static)|(near initialization)" } */
+ struct str d = (struct str) { 2, "d" }; /* { dg-error "(non-static)|(near initialization)" } */
+ struct str e = (struct str) { d.len, "e" }; /* { dg-error "(non-static)|(initialization)" } */
+}