if (init == void_node)
/* Trivial default-init, don't do anything to the CONSTRUCTOR. */
return ctx->ctor;
- eltinit = cxx_eval_constant_expression (&new_ctx, init, lval,
+ eltinit = init;
+ if (CLASS_TYPE_P (elttype) && new_ctx.object)
+ /* Clarify what object is being initialized (118285). */
+ eltinit = build2 (INIT_EXPR, elttype, new_ctx.object, eltinit);
+ eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
non_constant_p, overflow_p);
reuse = i == 0;
}
eltinit = (perform_implicit_conversion_flags
(elttype, eltinit, complain,
LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING));
+ if (CLASS_TYPE_P (elttype) && new_ctx.object)
+ /* Clarify what object is being initialized (118285). */
+ eltinit = build2 (INIT_EXPR, elttype, new_ctx.object, eltinit);
eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
non_constant_p, overflow_p);
}
--- /dev/null
+// PR c++/118285
+// { dg-do compile { target c++20 } }
+
+#include <initializer_list>
+
+struct A {
+ char *a;
+ union { char b[8]; long c; };
+ constexpr A (const char *x) : a(b)
+ {
+ for (int i = 0; i < 8; ++i)
+ b[i] = 0;
+ }
+ constexpr ~A ()
+ {
+ if (!foo ())
+ bar (c);
+ }
+ constexpr bool foo ()
+ {
+ char *x = a;
+ if (x == b)
+ return true;
+ return false;
+ }
+ constexpr void bar (long) {}
+};
+
+constexpr void
+baz (std::initializer_list<A>)
+{
+}
+
+constexpr bool
+qux ()
+{
+ baz ({""});
+ return true;
+}
+
+static_assert (qux (), "");