]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/13574 (array default initializer in class lets gcc consume all...
authorGabriel Dos Reis <gdr@integrable-solutions.net>
Wed, 21 Jan 2004 08:06:38 +0000 (08:06 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Wed, 21 Jan 2004 08:06:38 +0000 (08:06 +0000)
Backport from mainline
2004-01-16  Mark Mitchell  <mark@codesourcery.com>

 PR c++/13574
 * decl.c (compute_array_index_type): Fix grammar in comment.
 * init.c (build_zero_init): Handle zero-sized arrays correctly.

From-SVN: r76265

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/init.c
gcc/testsuite/g++.dg/ext/array1.C

index ece486368b1a2b1ef5f2f61524c98ac1ae2db00a..225c02d5cf4301d5fadf478006e932db7db1bd56 100644 (file)
@@ -1,3 +1,12 @@
+2004-01-21  Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+       Backport from mainline
+       2004-01-16  Mark Mitchell  <mark@codesourcery.com>
+       PR c++/13574
+       * decl.c (compute_array_index_type): Fix grammar in comment.
+       * init.c (build_zero_init): Handle zero-sized arrays correctly.
+       
 2004-01-21  Gabriel Dos Reis <gdr@integrable-solutions.net>
 
        Backport from mainline
index a70e9941a04016f9b8f0c2c69dad9f74988c2aca..6dda5dbbd3112ea9bb4421493593f27d1c55f4f2 100644 (file)
@@ -10176,9 +10176,8 @@ compute_array_index_type (name, size)
            error ("size of array is negative");
          size = integer_one_node;
        }
-      /* Except that an extension we allow zero-sized arrays.  We
-        always allow them in system headers because glibc uses
-        them.  */
+      /* As an extension we allow zero-sized arrays.  We always allow
+         them in system headers because glibc uses them.  */
       else if (integer_zerop (size) && pedantic && !in_system_header)
        {
          if (name)
index 5457ac56a1a2aca8b0b757bb2f8d6a31dcd6262f..ba30a9b6177407cda3b3ce28a3a4f4000ab4fcc5 100644 (file)
@@ -245,15 +245,18 @@ build_zero_init (tree type, tree nelts, bool static_storage_p)
       max_index = nelts ? nelts : array_type_nelts (type);
       my_friendly_assert (TREE_CODE (max_index) == INTEGER_CST, 20030618);
 
-      for (index = size_zero_node;
-          !tree_int_cst_lt (max_index, index);
-          index = size_binop (PLUS_EXPR, index, size_one_node))
-       inits = tree_cons (index,
-                          build_zero_init (TREE_TYPE (type),
-                                           /*nelts=*/NULL_TREE,
-                                           static_storage_p),
-                          inits);
-      CONSTRUCTOR_ELTS (init) = nreverse (inits);
+      /* A zero-sized array, which is accepted as an extension, will
+         have an upper bound of -1.  */
+      if (!tree_int_cst_equal (max_index, integer_minus_one_node))
+        for (index = size_zero_node;
+             !tree_int_cst_lt (max_index, index);
+             index = size_binop (PLUS_EXPR, index, size_one_node))
+          inits = tree_cons (index,
+                             build_zero_init (TREE_TYPE (type),
+                                              /*nelts=*/NULL_TREE,
+                                              static_storage_p),
+                             inits);
+         CONSTRUCTOR_ELTS (init) = nreverse (inits);
     }
   else if (TREE_CODE (type) == REFERENCE_TYPE)
     ;
index 7e54dc91939bfa33ebda813cc254c4300ee2b61d..d37cf912adc0bb88daeec45cd136a5662a7fa91e 100644 (file)
@@ -1,14 +1,14 @@
 // PR c++/13574
 // { dg-options "" }
 
-class A { 
-public: 
-  A() : argc(0), argv() { }; 
-private: 
-  int argc; 
-  char* argv[]; 
-}; 
-int main() { 
-  A y; 
+class A {
+public:
+  A() : argc(0), argv() { };
+  private:
+  int argc;
+  char* argv[];
+};
+
+int main() {
+  A y;
 }