PR c++/18384, c++/18327
authorJakub Jelinek <jakub@redhat.com>
Thu, 10 Mar 2005 14:19:51 +0000 (15:19 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 10 Mar 2005 14:19:51 +0000 (15:19 +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/array19.C: New test.

From-SVN: r96236

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

index 0665b65..5c02ee9 100644 (file)
@@ -1,3 +1,10 @@
+2005-03-10  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).
+
 2005-03-09  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/20208
index c253028..dee5c46 100644 (file)
@@ -4099,13 +4099,18 @@ 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 (fold_convert (size_type_node, max_index),
+                                     1);
+    }
 
   /* Loop until there are no more initializers.  */
   for (index = 0;
@@ -4122,27 +4127,16 @@ reshape_init_array (tree elt_type, tree max_index,
       CONSTRUCTOR_ELTS (new_init) = element_init;
       designated_index = TREE_PURPOSE (element_init);
       if (designated_index)
-      {
+       {
          /* Handle array designated initializers (GNU extension).  */
          if (TREE_CODE (designated_index) == IDENTIFIER_NODE)
            {
              error ("name %qD used in a GNU-style designated "
-                     "initializer for an array", designated_index);
+                    "initializer for an array", designated_index);
              TREE_PURPOSE (element_init) = NULL_TREE;
            }
          else
-           {
-             gcc_assert (TREE_CODE (designated_index) == INTEGER_CST);
-             if (sized_array_p
-                 && tree_int_cst_lt (max_index, designated_index))
-               {
-                 error ("Designated initializer %qE larger than array "
-                        "size", designated_index);
-                 TREE_PURPOSE (element_init) = NULL_TREE;
-               }
-             else
-               index = tree_low_cst (designated_index, 1);
-           }
+           gcc_unreachable ();
        }
     }
 
index 53daac0..be5388f 100644 (file)
@@ -1,5 +1,8 @@
 2005-03-10  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/18384, c++/18327
+       * g++.dg/init/array19.C: New test.
+
        PR inline-asm/20314
        * gcc.dg/torture/pr20314-1.c: New test.
        * gcc.dg/torture/pr20314-2.c: New test.
diff --git a/gcc/testsuite/g++.dg/init/array19.C b/gcc/testsuite/g++.dg/init/array19.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] = { };