From a8e6c82ab09c4c7a8490bc3861049b1941b84c75 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Fri, 16 Jan 2004 19:28:11 +0000 Subject: [PATCH] re PR c++/13574 (array default initializer in class lets gcc consume all memory and die) 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++/13574 * g++.dg/ext/array1.C: New test. From-SVN: r75991 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/decl.c | 5 ++--- gcc/cp/init.c | 19 +++++++++++-------- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/ext/array1.C | 14 ++++++++++++++ 5 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/array1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c773f165dcc2..fb2b43dd98a3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -4,6 +4,10 @@ 2004-01-16 Mark Mitchell + 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 625f94b7048a..b95cf1e61713 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 1dc5d9d145fb..e74a5980098c 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 d23fe5dc2829..d08f1feee163 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2004-01-16 Mark Mitchell + 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 000000000000..7e54dc91939b --- /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; +} -- 2.47.3