between zero-length arrays and flexible arrays.
(push_init_level): Detect zero-length arrays and handle them
like fixed-sized arrays.
* expr.c (store_constructor): Handle zero-length arrays and
flexible arrays correctly.
* doc/extend.texi: Update zero-length array notes.
* gcc.dg/
20000926-1.c: Update expected warning messages.
* gcc.dg/array-2.c: Likewise, and test for warnings too.
* gcc.dg/array-4.c: Likewise, and don't verify the zero-length
array.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45714
138bc75d-0d04-0410-961f-
82ee72b054a4
+2001-09-20 DJ Delorie <dj@redhat.com>
+
+ * c-typeck.c (really_start_incremental_init): Discriminate
+ between zero-length arrays and flexible arrays.
+ (push_init_level): Detect zero-length arrays and handle them
+ like fixed-sized arrays.
+ * expr.c (store_constructor): Handle zero-length arrays and
+ flexible arrays correctly.
+ * doc/extend.texi: Update zero-length array notes.
+
2001-09-20 Jim Wilson <wilson@redhat.com>
* config/ia64/ia64.c (itanium_split_issue): Allow max 2 FP per cycle.
= TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
/* Detect non-empty initializations of zero-length arrays. */
- if (constructor_max_index == NULL_TREE)
+ if (constructor_max_index == NULL_TREE
+ && TYPE_SIZE (constructor_type))
constructor_max_index = build_int_2 (-1, -1);
constructor_index
{
constructor_max_index
= TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
+
+ /* Detect non-empty initializations of zero-length arrays. */
+ if (constructor_max_index == NULL_TREE
+ && TYPE_SIZE (constructor_type))
+ constructor_max_index = build_int_2 (-1, -1);
+
constructor_index
= convert (bitsizetype,
TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
-
- /* ??? For GCC 3.1, remove special case initialization of
- zero-length array members from pop_init_level and set
- constructor_max_index such that we get the normal
- "excess elements" warning. */
}
else
constructor_index = bitsize_zero_node;
constructor_type = NULL_TREE;
}
else
- {
- warning_init ("deprecated initialization of zero-length array");
-
- /* We must be initializing the last member of a top-level struct. */
- if (TREE_CHAIN (constructor_fields) != NULL_TREE)
- {
- error_init ("initialization of zero-length array before end of structure");
- /* Discard the initializer so that we do not abort later. */
- constructor_type = NULL_TREE;
- }
- else if (constructor_depth > 2)
- error_init ("initialization of zero-length array inside a nested context");
- }
+ /* Zero-length arrays are no longer special, so we should no longer
+ get here. */
+ abort();
}
/* Warn when some struct elements are implicitly initialized to zero. */
@item
Flexible array members may only appear as the last member of a
-@code{struct} that is otherwise non-empty. GCC currently allows
-zero-length arrays anywhere. You may encounter problems, however,
-defining structures containing only a zero-length array. Such usage
-is deprecated, and we recommend using zero-length arrays only in
-places in which flexible array members would be allowed.
+@code{struct} that is otherwise non-empty.
@end itemize
GCC versions before 3.0 allowed zero-length arrays to be statically
-initialized. In addition to those cases that were useful, it also
-allowed initializations in situations that would corrupt later data.
-Non-empty initialization of zero-length arrays is now deprecated.
+initialized, as if they were flexible arrays. In addition to those
+cases that were useful, it also allowed initializations in situations
+that would corrupt later data. Non-empty initialization of zero-length
+arrays is now treated like any case where there are more initializer
+elements than the array holds, in that a suitable warning about "excess
+elements in array" is given, and the excess elements (all of them, in
+this case) are ignored.
Instead GCC allows static initialization of flexible array members.
This is equivalent to defining a new structure containing the original
int need_to_clear;
tree domain = TYPE_DOMAIN (type);
tree elttype = TREE_TYPE (type);
- int const_bounds_p = (host_integerp (TYPE_MIN_VALUE (domain), 0)
+ int const_bounds_p = (TYPE_MIN_VALUE (domain)
+ && TYPE_MAX_VALUE (domain)
+ && host_integerp (TYPE_MIN_VALUE (domain), 0)
&& host_integerp (TYPE_MAX_VALUE (domain), 0));
HOST_WIDE_INT minelt = 0;
HOST_WIDE_INT maxelt = 0;
+2001-09-20 DJ Delorie <dj@redhat.com>
+
+ * gcc.dg/20000926-1.c: Update expected warning messages.
+ * gcc.dg/array-2.c: Likewise, and test for warnings too.
+ * gcc.dg/array-4.c: Likewise, and don't verify the zero-length
+ array.
+
2001-09-18 Richard Sandiford <rsandifo@redhat.com>
* g++.dg/eh/registers1.C: New test case.
{
"BookName",
{
- { 1, "PName0" },
- } /* { dg-warning "(deprecated initialization)|(near initialization)" "" } */
+ { 1, "PName0" }, /* { dg-warning "(excess elements)|(near initialization)" "" } */
+ }
};
/* { dg-do compile } */
-/* { dg-options "-w" } */
+/* { dg-options "" } */
/* Verify that we can't do things to get ourselves in trouble
with GCC's initialized flexible array member extension. */
struct g g2 = { { 0, { 1 } } }; /* { dg-error "(nested context)|(near initialization)" "nested" } */
struct h { int x[0]; int y; };
-struct h h1 = { { 0 }, 1 }; /* { dg-error "(before end)|(near initialization)" "before end" } */
+struct h h1 = { { 0 }, 1 }; /* { dg-error "(excess elements)|(near initialization)" "before end" } */
static struct f f = { 4, { 0, 1, 2, 3 } };
static int junk1[] = { -1, -1, -1, -1 };
-static struct g g = { 4, { 0, 1, 2, 3 } }; /* { dg-warning "(deprecated initialization)|(near initialization)" "" } */
+static struct g g = { 4, { 0, 1, 2, 3 } }; /* { dg-warning "(excess elements)|(near initialization)" "" } */
static int junk2[] = { -1, -1, -1, -1 };
int main()
for (i = 0; i < f.w; ++i)
if (f.x[i] != i)
abort ();
- for (i = 0; i < g.w; ++i)
- if (g.x[i] != i)
- abort ();
exit(0);
}