OSDN Git Service

PR c++/13574
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 16 Jan 2004 19:28:11 +0000 (19:28 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 16 Jan 2004 19:28:11 +0000 (19:28 +0000)
* decl.c (compute_array_index_type): Fix grammar in comment.
* init.c (build_zero_init): Handle zero-sized arrays correctly.

PR c++/13574
* g++.dg/ext/array1.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@75991 138bc75d-0d04-0410-961f-82ee72b054a4

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

index c773f16..fb2b43d 100644 (file)
@@ -4,6 +4,10 @@
 
 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.
+
        PR c++/13178
        * call.c (name_as_c_string): Print conversion operator names
        correctly.
index 625f94b..b95cf1e 100644 (file)
@@ -6079,9 +6079,8 @@ compute_array_index_type (tree name, tree 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 1dc5d9d..e74a598 100644 (file)
@@ -228,14 +228,17 @@ 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);
+      /* 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 d23fe5d..d08f1fe 100644 (file)
@@ -1,5 +1,8 @@
 2004-01-16  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/13574
+       * g++.dg/ext/array1.C: New test.
+
        PR c++/13178
        * g++.dg/conversion/op1.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/ext/array1.C b/gcc/testsuite/g++.dg/ext/array1.C
new file mode 100644 (file)
index 0000000..7e54dc9
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/13574
+// { dg-options "" }
+
+class A { 
+public: 
+  A() : argc(0), argv() { }; 
+private: 
+  int argc; 
+  char* argv[]; 
+}; 
+int main() { 
+  A y; 
+}