This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix up array initializations from compound literal (PR c++/40948)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 3 Aug 2009 19:17:28 +0200
- Subject: [C++ PATCH] Fix up array initializations from compound literal (PR c++/40948)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
As discussed in the PR, the attached testcase fails to compile, because
the GIMPLE_WITH_CLEANUP_EXPR created for the compound literal's cleanup
isn't seen by its CLEANUP_EXPR, because build_vec_init adds an explicit
TRY_BLOCK which is inside of the CLEANUP_EXPR argument and around the
TARGET_EXPR which needs its own cleanup.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux.
Ok for trunk/4.4?
2009-08-03 Jakub Jelinek <jakub@redhat.com>
PR c++/40948
* init.c (build_vec_init): Add CLEANUP_POINT_EXPR around
TRY_STMTS (try_block).
* g++.dg/ext/complit12.C: New test.
--- gcc/cp/init.c.jj 2009-07-20 20:41:55.000000000 +0200
+++ gcc/cp/init.c 2009-08-03 17:04:03.000000000 +0200
@@ -2928,6 +2928,11 @@ build_vec_init (tree base, tree maxindex
inner_elt_type, sfk_base_destructor,
/*use_global_delete=*/0);
finish_cleanup (e, try_block);
+
+ if (!processing_template_decl)
+ TRY_STMTS (try_block)
+ = fold_build_cleanup_point_expr (void_type_node,
+ TRY_STMTS (try_block));
}
/* The value of the array initialization is the array itself, RVAL
--- gcc/testsuite/g++.dg/ext/complit12.C.jj 2009-08-03 17:07:47.000000000 +0200
+++ gcc/testsuite/g++.dg/ext/complit12.C 2009-08-03 17:08:21.000000000 +0200
@@ -0,0 +1,37 @@
+// PR c++/40948
+// { dg-do compile }
+// { dg-options "" }
+
+struct M
+{
+ M () {}
+ ~M () {}
+};
+
+struct S
+{
+ S ();
+ M m[1];
+};
+
+S::S () : m ((M[1]) { M () })
+{
+}
+
+struct T
+{
+ T ();
+ M m[4];
+};
+
+T::T () : m ((M[4]) { M (), M (), M (), M () })
+{
+}
+
+void
+foo ()
+{
+ M m[1] = (M[1]) { M () };
+ M n = (M) { M () };
+ M o[4] = (M[4]) { M (), M (), M (), M () };
+}
Jakub