We were always calling the complete destructor if the target constructor
throws, even if we were calling the base constructor.
PR c++/103711
gcc/cp/ChangeLog:
* init.c (perform_target_ctor): Select destructor by in_chrg.
gcc/testsuite/ChangeLog:
* g++.dg/eh/delegating1.C: New test.
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR,
0, tf_warning_or_error);
+ if (DECL_HAS_IN_CHARGE_PARM_P (current_function_decl))
+ {
+ tree base = build_delete (input_location,
+ type, decl, sfk_base_destructor,
+ LOOKUP_NORMAL
+ |LOOKUP_NONVIRTUAL
+ |LOOKUP_DESTRUCTOR,
+ 0, tf_warning_or_error);
+ expr = build_if_in_charge (expr, base);
+ }
if (expr != error_mark_node
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
finish_eh_cleanup (expr);
--- /dev/null
+// PR c++/103711
+// { dg-do run { target c++11 } }
+
+int constructions = 0;
+int destructions = 0;
+
+struct A
+{
+ A() { constructions++; }
+ virtual ~A() { destructions++; }
+};
+
+struct B : public virtual A
+{
+ B(int) { }
+ B() : B(1) { throw -1; }
+ virtual ~B() = default;
+};
+
+struct C : public B { };
+
+int main() {
+ try {
+ C c;
+ }
+ catch (int) {}
+ return (constructions - destructions);
+}