commit 7d32708956095f3ddb6698fee9fa092f649d72d4
Author: Jason Merrill <jason@redhat.com>
Date: Thu Oct 20 15:00:49 2011 -0400
PR c++/41449
* typeck2.c (split_nonconstant_init_1): Handle EH cleanup of
initialized subobjects.
@@ -567,6 +567,13 @@ split_nonconstant_init_1 (tree dest, tree init)
code = build2 (INIT_EXPR, inner_type, sub, value);
code = build_stmt (input_location, EXPR_STMT, code);
add_stmt (code);
+ if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (inner_type))
+ {
+ code = (build_special_member_call
+ (sub, complete_dtor_identifier, NULL, inner_type,
+ LOOKUP_NORMAL, tf_warning_or_error));
+ finish_eh_cleanup (code);
+ }
num_split_elts++;
}
new file mode 100644
@@ -0,0 +1,37 @@
+// PR c++/41449
+// { dg-do run }
+
+struct A
+{
+ A() {}
+ A(const A&) { throw 1; }
+};
+
+int bs;
+struct B
+{
+ B() { ++bs; }
+ B(const B&) { ++bs; }
+ ~B() { --bs; }
+};
+
+struct C
+{
+ B b1;
+ A a;
+ B b2;
+};
+
+int main()
+{
+ {
+ B b1, b2;
+ A a;
+
+ try {
+ C c = { b1, a, b2 };
+ } catch (...) {}
+ }
+ if (bs != 0)
+ __builtin_abort ();
+}