{
for (tree t : *cleanups)
{
- push_cleanup (decl, t, false);
+ push_cleanup (NULL_TREE, t, false);
/* As in initialize_local_var. */
wrap_temporary_cleanups (init, t);
}
init = build2 (INIT_EXPR, type, decl, init);
finish_expr_stmt (init);
FOR_EACH_VEC_ELT (*cleanups, i, t)
- push_cleanup (decl, t, false);
+ push_cleanup (NULL_TREE, t, false);
}
else if (type_build_ctor_call (type)
|| (init && CLASS_TYPE_P (strip_array_types (type))))
/* Queue a cleanup. CLEANUP is an expression/statement to be executed
when the current scope is exited. EH_ONLY is true when this is not
- meant to apply to normal control flow transfer. */
+ meant to apply to normal control flow transfer. DECL is the VAR_DECL
+ being cleaned up, if any, or null for temporaries or subobjects. */
void
push_cleanup (tree decl, tree cleanup, bool eh_only)
--- /dev/null
+// PR c++/101442
+// { dg-do run { target c++11 } }
+
+bool destroyed = false;
+
+struct A
+{
+ A() {}
+ A(const A &) = delete;
+ A &operator=(const A &) = delete;
+ ~A() {destroyed = true;}
+};
+
+struct B
+{
+ const A &a;
+ struct string {
+ string(const char*) { }
+ ~string() { }
+ } s;
+};
+
+B foo()
+{
+ B ret{ A{}, "" };
+ return ret;
+}
+
+int main()
+{
+ B b = foo();
+ if (!destroyed)
+ __builtin_abort();
+}