aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/decl.c5
-rw-r--r--gcc/cp/init.c19
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/ext/array1.C14
5 files changed, 34 insertions, 11 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c773f16..fb2b43d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 625f94b..b95cf1e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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)
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 1dc5d9d..e74a598 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -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)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d23fe5d..d08f1fe 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..7e54dc9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/array1.C
@@ -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;
+}