aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>2002-07-03 15:46:21 +0000
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>2002-07-03 15:46:21 +0000
commitb2153b98f202a261b77be7be529d371bb9fd3907 (patch)
tree9ba586fc93e9ae7cc750165df2c4b65dd0a3ded0 /gcc
parent61c07d3c9ba1d6351bbefc0227e526b905a63839 (diff)
downloadgcc-b2153b98f202a261b77be7be529d371bb9fd3907.zip
gcc-b2153b98f202a261b77be7be529d371bb9fd3907.tar.gz
gcc-b2153b98f202a261b77be7be529d371bb9fd3907.tar.bz2
re PR c++/6944 (missing feature on default copy-constructor for class with multi-dim arrays)
PR c++/6944 * init.c (build_aggr_init): Remove qualifiers of init before calling build_vec_init. (build_vec_init): Flatten multi-dimensional array during cleanup. (build_vec_delete_1): Abort if the type of each element is array. * g++.dg/init/array4.C: New test. * g++.dg/init/array5.C: New test. From-SVN: r55214
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/init.c26
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/init/array4.C27
-rw-r--r--gcc/testsuite/g++.dg/init/array5.C52
5 files changed, 111 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0f4f6a0..bc42127 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2002-07-03 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+
+ PR c++/6944
+ * init.c (build_aggr_init): Remove qualifiers of init before calling
+ build_vec_init.
+ (build_vec_init): Flatten multi-dimensional array during cleanup.
+ (build_vec_delete_1): Abort if the type of each element is array.
+
2002-07-03 Graham Stott <graham.stott@btinternet.com>
* pt.c (instantiate_class_template): Fix typo.
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 0c34c05..7f23699 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -1161,11 +1161,9 @@ build_aggr_init (exp, init, flags)
return error_mark_node;
}
if (cp_type_quals (type) != TYPE_UNQUALIFIED)
- {
- TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type);
- if (init)
- TREE_TYPE (init) = TYPE_MAIN_VARIANT (itype);
- }
+ TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type);
+ if (itype && cp_type_quals (itype) != TYPE_UNQUALIFIED)
+ TREE_TYPE (init) = TYPE_MAIN_VARIANT (itype);
stmt_expr = build_vec_init (exp, init,
init && same_type_p (TREE_TYPE (init),
TREE_TYPE (exp)));
@@ -2586,6 +2584,10 @@ build_vec_delete_1 (base, maxindex, type, auto_delete_vec, use_global_delete)
This is also the containing expression returned by this function. */
tree controller = NULL_TREE;
+ /* We should only have 1-D arrays here. */
+ if (TREE_CODE (type) == ARRAY_TYPE)
+ abort ();
+
if (! IS_AGGR_TYPE (type) || TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
{
loop = integer_zero_node;
@@ -3002,12 +3004,20 @@ build_vec_init (base, init, from_array)
&& from_array != 2)
{
tree e;
+ tree m = cp_build_binary_op (MINUS_EXPR, maxindex, iterator);
+
+ /* Flatten multi-dimensional array since build_vec_delete only
+ expects one-dimensional array. */
+ if (TREE_CODE (type) == ARRAY_TYPE)
+ {
+ m = cp_build_binary_op (MULT_EXPR, m,
+ array_type_nelts_total (type));
+ type = strip_array_types (type);
+ }
finish_compound_stmt (/*has_no_scope=*/1, try_body);
finish_cleanup_try_block (try_block);
- e = build_vec_delete_1 (rval,
- cp_build_binary_op (MINUS_EXPR, maxindex,
- iterator),
+ e = build_vec_delete_1 (rval, m,
type,
sfk_base_destructor,
/*use_global_delete=*/0);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9daae1a..c4146af 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2002-07-03 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+
+ PR c++/6944
+ * g++.dg/init/array4.C: New test.
+ * g++.dg/init/array5.C: New test.
+
Wed Jul 3 10:25:41 2002 J"orn Rennecke <joern.rennecke@superh.com>
* gcc.c-torture/execute/simd-1.c (main): Also test &, |, ^, ~.
diff --git a/gcc/testsuite/g++.dg/init/array4.C b/gcc/testsuite/g++.dg/init/array4.C
new file mode 100644
index 0000000..67519bf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/array4.C
@@ -0,0 +1,27 @@
+// { dg-do compile }
+// Origin: Markus Breuer <markus.breuer@materna.de>
+
+// PR c++/6944
+// Fail to synthesize copy constructor of multi-dimensional
+// array of class.
+
+#include <string>
+
+class Array
+{
+public:
+ std::string m_array[10][20][30];
+};
+
+Array func()
+{
+ Array result;
+ return result; // sorry, not implemented: cannot initialize multi-dimensional array with initializer
+}
+
+
+int main()
+{
+ Array arr = func();
+}
+
diff --git a/gcc/testsuite/g++.dg/init/array5.C b/gcc/testsuite/g++.dg/init/array5.C
new file mode 100644
index 0000000..aeacb31
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/array5.C
@@ -0,0 +1,52 @@
+// { dg-do run }
+// Copyright (C) 2002 Free Software Foundation
+// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+
+// Incorrect construction and destruction of multi-dimensional
+// array of class.
+
+extern "C" void abort();
+extern "C" int printf(const char *, ...);
+
+int count;
+int num;
+
+struct A
+{
+ A()
+ {
+ if (count == num)
+ throw "";
+ count++;
+#ifdef PRINT
+ printf("ctor %p\n", static_cast<void *>(this));
+#endif
+ }
+
+ ~A()
+ {
+ count--;
+#ifdef PRINT
+ printf("dtor %p\n", static_cast<void *>(this));
+#endif
+ }
+};
+
+struct Array
+{
+ A array[2][2][2];
+};
+
+int main()
+{
+ for (num = 0; num <= 8; ++num) {
+ count = 0;
+ try {
+ Array A;
+ }
+ catch (...) {
+ }
+ if (count != 0)
+ abort();
+ }
+}