]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-typeck.c (really_start_incremental_init): Discriminate between zero-length arrays...
authorDJ Delorie <dj@redhat.com>
Fri, 21 Sep 2001 00:27:59 +0000 (20:27 -0400)
committerDJ Delorie <dj@gcc.gnu.org>
Fri, 21 Sep 2001 00:27:59 +0000 (20:27 -0400)
* 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.

* 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.

From-SVN: r45714

gcc/ChangeLog
gcc/c-typeck.c
gcc/doc/extend.texi
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/20000926-1.c
gcc/testsuite/gcc.dg/array-2.c
gcc/testsuite/gcc.dg/array-4.c

index c0190fc2cd6172e150c8f9555721fcc7aefc6cfd..1419033057b7fee583967a9ca628e2a95a7ac796 100644 (file)
@@ -1,3 +1,13 @@
+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.
index 3298062e8d7023fed0e84718ec6b6588f73f1a9f..c3d11fe731694b4b9a87a5ec3d572f1950351df7 100644 (file)
@@ -5190,7 +5190,8 @@ really_start_incremental_init (type)
            = 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
@@ -5352,14 +5353,15 @@ push_init_level (implicit)
        {
          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;
@@ -5438,19 +5440,9 @@ pop_init_level (implicit)
            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.  */
index 05a2e5854e66404b8db02656c88de35ae13ea137..08344960b52820dc79f3e10bc8f2bb0963ea8333 100644 (file)
@@ -1303,17 +1303,17 @@ of zero-length arrays, @code{sizeof} evaluates 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
index 3d0d93a6a64488e6e931cd2445e3f90c290958a4..b61fc176ed769a5a696340b6fa9f5ed646d5c9b1 100644 (file)
@@ -4710,7 +4710,9 @@ store_constructor (exp, target, align, cleared, size)
       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;
index 7f28c4cb0cf47fb0d3f79b18d79751cf3f546655..16d4816af73d5e881236fe6223eb26ac0f32ac1c 100644 (file)
@@ -1,3 +1,10 @@
+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.
index 223714d20b5ca63fc0ac259802659ade20b985f3..2f5ca10a1ba8197fea08acb34b0337a1354e28ff 100644 (file)
@@ -22,6 +22,6 @@ struct PLAYBOOK playbook  =
 {
   "BookName",
   {
-    { 1, "PName0" },
-  } /* { dg-warning "(deprecated initialization)|(near initialization)" "" } */
+    { 1, "PName0" }, /* { dg-warning "(excess elements)|(near initialization)" "" } */
+  }
 };
index dbf1733697d2cbfcd1e2587eef5dfa78dbce0952..06c753f63216be70f8d5e2204b84bc164d9b2a22 100644 (file)
@@ -1,5 +1,5 @@
 /* { 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.  */
@@ -10,4 +10,4 @@ struct g g1 = { { 0, { } } };
 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" } */
index 52ad92143a55c761f7c956656adc40e3ddcb73d4..b3e4f6c50dedc8ac4432fe1d9d8ec9c9a8310861 100644 (file)
@@ -12,7 +12,7 @@ struct g { int w; int x[0]; };
 
 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()
@@ -21,8 +21,5 @@ 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);
 }