if (init && TREE_CODE (init) != TREE_VEC)
{
- /* In aggregate initialization of a variable, each element
- initialization is a full-expression because there is no
- enclosing expression. */
- gcc_assert (stmts_are_full_exprs_p ());
-
init_code = store_init_value (decl, init, cleanups, flags);
if (DECL_INITIAL (decl)
tree guard = (tree)data;
tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
- if (tcleanup && !expr_noexcept_p (tcleanup, tf_none))
+ if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
+ && !expr_noexcept_p (tcleanup, tf_none))
{
tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
/* Tell honor_protect_cleanup_actions to handle this as a separate
{
tree rinit = (TREE_CODE (init) == INIT_EXPR
? TREE_OPERAND (init, 1) : NULL_TREE);
- if (rinit && !TREE_SIDE_EFFECTS (rinit))
+ if (rinit && !TREE_SIDE_EFFECTS (rinit)
+ && TREE_OPERAND (init, 0) == decl)
{
/* Stick simple initializers in DECL_INITIAL so that
-Wno-init-self works (c++/34772). */
- gcc_assert (TREE_OPERAND (init, 0) == decl);
DECL_INITIAL (decl) = rinit;
if (warn_init_self && TYPE_REF_P (type))
}
\f
+/* We've just initialized subobject SUB; also insert a TARGET_EXPR with an
+ EH-only cleanup for SUB. Because of EH region nesting issues, we need to
+ make the cleanup conditional on a flag that we will clear once the object is
+ fully initialized, so push a new flag onto FLAGS. */
+
+static void
+maybe_push_temp_cleanup (tree sub, vec<tree,va_gc> **flags)
+{
+ if (tree cleanup
+ = cxx_maybe_build_cleanup (sub, tf_warning_or_error))
+ {
+ tree tx = get_target_expr (boolean_true_node);
+ tree flag = TARGET_EXPR_SLOT (tx);
+ CLEANUP_EH_ONLY (tx) = true;
+ TARGET_EXPR_CLEANUP (tx) = build3 (COND_EXPR, void_type_node,
+ flag, cleanup, void_node);
+ add_stmt (tx);
+ vec_safe_push (*flags, flag);
+ }
+}
+
/* The recursive part of split_nonconstant_init. DEST is an lvalue
expression to which INIT should be assigned. INIT is a CONSTRUCTOR.
Return true if the whole of the value was initialized by the
generated statements. */
static bool
-split_nonconstant_init_1 (tree dest, tree init, bool nested)
+split_nonconstant_init_1 (tree dest, tree init, bool nested, vec<tree,va_gc> **flags)
{
unsigned HOST_WIDE_INT idx, tidx = HOST_WIDE_INT_M1U;
tree field_index, value;
if (nested)
/* Also clean up the whole array if something later in an enclosing
init-list throws. */
- if (tree cleanup = cxx_maybe_build_cleanup (dest,
- tf_warning_or_error))
- finish_eh_cleanup (cleanup);
+ maybe_push_temp_cleanup (dest, flags);
return true;
}
/* FALLTHRU */
sub = build3 (COMPONENT_REF, inner_type, dest, field_index,
NULL_TREE);
- if (!split_nonconstant_init_1 (sub, value, true)
+ if (!split_nonconstant_init_1 (sub, value, true, flags)
/* For flexible array member with initializer we
can't remove the initializer, because only the
initializer determines how many elements the
code = build2 (INIT_EXPR, inner_type, sub, value);
}
code = build_stmt (input_location, EXPR_STMT, code);
- code = maybe_cleanup_point_expr_void (code);
add_stmt (code);
- if (tree cleanup
- = cxx_maybe_build_cleanup (sub, tf_warning_or_error))
- finish_eh_cleanup (cleanup);
+ maybe_push_temp_cleanup (sub, flags);
}
num_split_elts++;
init = TARGET_EXPR_INITIAL (init);
if (TREE_CODE (init) == CONSTRUCTOR)
{
+ /* Subobject initializers are not full-expressions. */
+ auto fe = (make_temp_override
+ (current_stmt_tree ()->stmts_are_full_exprs_p, 0));
+
init = cp_fully_fold_init (init);
code = push_stmt_list ();
- if (split_nonconstant_init_1 (dest, init, false))
+
+ /* Collect flags for disabling subobject cleanups once the complete
+ object is fully constructed. */
+ vec<tree, va_gc> *flags = make_tree_vector ();
+
+ if (split_nonconstant_init_1 (dest, init, false, &flags))
init = NULL_TREE;
+
+ for (tree f : flags)
+ {
+ /* See maybe_push_temp_cleanup. */
+ tree d = f;
+ tree i = boolean_false_node;
+ add_stmt (build2 (MODIFY_EXPR, TREE_TYPE (d), d, i));
+ }
+ release_tree_vector (flags);
+
code = pop_stmt_list (code);
if (VAR_P (dest) && !is_local_temp (dest))
{