]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/18384, c++/18327
authorJakub Jelinek <jakub@redhat.com>
Tue, 28 Dec 2004 20:57:56 +0000 (21:57 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 28 Dec 2004 20:57:56 +0000 (21:57 +0100)
PR c++/18384, c++/18327
* decl.c (reshape_init_array): Use UHWI type for max_index_cst
and index.  Convert max_index to size_type_node if it isn't
host_integerp (, 1).

* g++.dg/init/array18.C: New test.

From-SVN: r92682

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/array18.C [new file with mode: 0644]

index f3cb473cea698b2b0b8d516d5655b434a5a3a68e..0d0051ea2db25bf0b8bdb07353e19f2832873c19 100644 (file)
@@ -1,3 +1,10 @@
+2004-12-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/18384, c++/18327
+       * decl.c (reshape_init_array): Use UHWI type for max_index_cst
+       and index.  Convert max_index to size_type_node if it isn't
+       host_integerp (, 1).
+
 2004-12-23  Alexandre Oliva  <aoliva@redhat.com>
 
        PR c++/18962
index 24a51d4b35a528e40b267216593c2ee93618c97a..61b618258d854e2275f0a8a53bdc6c58bef66383 100644 (file)
@@ -4210,13 +4210,17 @@ reshape_init_array (tree elt_type, tree max_index,
                    tree *initp, tree new_init)
 {
   bool sized_array_p = (max_index != NULL_TREE);
-  HOST_WIDE_INT max_index_cst = 0;
-  HOST_WIDE_INT index;
+  unsigned HOST_WIDE_INT max_index_cst = 0;
+  unsigned HOST_WIDE_INT index;
 
   if (sized_array_p)
-    /* HWI is either 32bit or 64bit, so it must be enough to represent the
-       array size.  */
-    max_index_cst = tree_low_cst (max_index, 1);
+    {
+      if (host_integerp (max_index, 1))
+       max_index_cst = tree_low_cst (max_index, 1);
+      /* sizetype is sign extended, not zero extended.  */
+      else
+       max_index_cst = tree_low_cst (convert (size_type_node, max_index), 1);
+    }
 
   /* Loop until there are no more initializers.  */
   for (index = 0;
@@ -4242,19 +4246,7 @@ reshape_init_array (tree elt_type, tree max_index,
              TREE_PURPOSE (element_init) = NULL_TREE;
            }
          else
-           {
-             if (TREE_CODE (designated_index) != INTEGER_CST)
-               abort ();
-             if (sized_array_p
-                 && tree_int_cst_lt (max_index, designated_index))
-               {
-                 error ("Designated initializer `%E' larger than array "
-                        "size", designated_index);
-                 TREE_PURPOSE (element_init) = NULL_TREE;
-               }
-             else
-               index = tree_low_cst (designated_index, 1);
-           }
+           abort ();
        }
     }
 
index e0df4c05a12f84fc66a781790998d81326196d4b..17a2ace54d5fdbaf5ebaaa86e36821dd6033d23c 100644 (file)
@@ -1,3 +1,8 @@
+2004-12-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/18384, c++/18327
+       * g++.dg/init/array18.C: New test.
+
 2004-12-23  Alexandre Oliva  <aoliva@redhat.com>
 
        PR target/16819
diff --git a/gcc/testsuite/g++.dg/init/array18.C b/gcc/testsuite/g++.dg/init/array18.C
new file mode 100644 (file)
index 0000000..a5f124e
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-options "" }
+double a[0] = { };
+const double b[0][1] = { };