The split_nonconstant_init piece is the only one necessary to fix the
testcase, but it occurred to me that we might as well not split when
-fno-exceptions.
* typeck2.c (split_nonconstant_init): Unshare non-decl.
* cp-gimplify.c (cp_gimplify_init_expr): Only split if -fexceptions.
From-SVN: r279871
+2020-01-03 Jason Merrill <jason@redhat.com>
+
+ PR c++/93033 - incorrect tree node sharing with array init.
+ * typeck2.c (split_nonconstant_init): Unshare non-decl.
+ * cp-gimplify.c (cp_gimplify_init_expr): Only split if -fexceptions.
+
2020-01-02 Jason Merrill <jason@redhat.com>
* pt.c (invalid_nontype_parm_type_p): Reject class placeholder in
/* If we might need to clean up a partially constructed object, break down
the CONSTRUCTOR with split_nonconstant_init. */
if (TREE_CODE (from) == CONSTRUCTOR
+ && flag_exceptions
&& TREE_SIDE_EFFECTS (from)
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (to)))
{
#include "intl.h"
#include "gcc-rich-location.h"
#include "target.h"
+#include "gimplify.h"
static tree
process_init_constructor (tree type, tree init, int nested, int flags,
}
else if (init)
{
- tree ie = build2 (INIT_EXPR, void_type_node, dest, init);
+ tree ie = build2 (INIT_EXPR, void_type_node,
+ unshare_expr (dest), init);
code = add_stmt_to_compound (ie, code);
}
}
--- /dev/null
+// PR c++/93033
+// { dg-do compile { target c++11 } }
+
+struct A {
+ A ();
+ ~A ();
+};
+
+A f();
+
+struct B {
+ A a;
+ bool b;
+};
+
+void
+foo ()
+{
+ B i[] { f() };
+}