diff options
author | rth <rth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-01-05 05:58:23 +0000 |
---|---|---|
committer | rth <rth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-01-05 05:58:23 +0000 |
commit | 21c8999d936bf4280e949c225c46fd0334508a9e (patch) | |
tree | f0375afbbd6220caa4aacf6320495224ac911480 /gcc/c-decl.c | |
parent | a707dc90e7f242dab97dee41aed6e2d8470c0c00 (diff) | |
download | gcc-21c8999d936bf4280e949c225c46fd0334508a9e.tar.gz |
* c-decl.c (finish_struct): Detect flexible array members
used in an inappropriate context.
* c-typeck.c (really_start_incremental_init): Special case
constructor_max_index for zero length arrays.
(pop_init_level): Allow initialization of flexible array
members. Deprecate initialization of zero length arrays.
Don't issue missing initializer warning for flexible array
members or zero length arrays.
(process_init_element): Don't dereference null DECL_SIZE.
* varasm.c (array_size_for_constructor): Return a HOST_WIDE_INT.
Don't abort for empty constructors. Use size_binop
(output_constructor): Add commentary regarding zero length
array futures. Abort if we try to initialize an array of
unspecified length with a non-empty constructor in the middle
of a structure.
* extend.texi (Zero Length): Update and clarify documentation
on static initialization.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38705 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index c813d3e42de..0a94db0e595 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -5200,6 +5200,7 @@ finish_struct (t, fieldlist, attributes) { register tree x; int toplevel = global_binding_level == current_binding_level; + int saw_named_field; /* If this type was previously laid out as a forward reference, make sure we lay it out again. */ @@ -5238,6 +5239,7 @@ finish_struct (t, fieldlist, attributes) Store 0 there, except for ": 0" fields (so we can find them and delete them, below). */ + saw_named_field = 0; for (x = fieldlist; x; x = TREE_CHAIN (x)) { DECL_CONTEXT (x) = t; @@ -5371,6 +5373,22 @@ finish_struct (t, fieldlist, attributes) } DECL_INITIAL (x) = 0; + + /* Detect flexible array member in an invalid context. */ + if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE + && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE + && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE + && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) + { + if (TREE_CODE (t) == UNION_TYPE) + error_with_decl (x, "flexible array member in union"); + else if (TREE_CHAIN (x) != NULL_TREE) + error_with_decl (x, "flexible array member not at end of struct"); + else if (! saw_named_field) + error_with_decl (x, "flexible array member in otherwise empty struct"); + } + if (DECL_NAME (x)) + saw_named_field = 1; } /* Delete all duplicate fields from the fieldlist */ @@ -5416,8 +5434,8 @@ finish_struct (t, fieldlist, attributes) fieldlistp = &TREE_CHAIN (*fieldlistp); } - /* Now we have the truly final field list. - Store it in this type and in the variants. */ + /* Now we have the truly final field list. + Store it in this type and in the variants. */ TYPE_FIELDS (t) = fieldlist; |