&jump_target);
if (DECL_CONSTRUCTOR_P (fun))
- /* This can be null for a subobject constructor call, in
- which case what we care about is the initialization
- side-effects rather than the value. We could get at the
- value by evaluating *this, but we don't bother; there's
- no need to put such a call in the hash table. */
- result = lval ? ctx->object : ctx->ctor;
+ {
+ /* This can be null for a subobject constructor call, in
+ which case what we care about is the initialization
+ side-effects rather than the value. We could get at the
+ value by evaluating *this, but we don't bother; there's
+ no need to put such a call in the hash table. */
+ result = lval ? ctx->object : ctx->ctor;
+
+ /* If we've just evaluated a subobject constructor call for an
+ empty union member, it might not have produced a side effect
+ that actually activated the union member. So produce such a
+ side effect now to ensure the union appears initialized. */
+ if (!result && new_obj
+ && TREE_CODE (new_obj) == COMPONENT_REF
+ && TREE_CODE (TREE_TYPE
+ (TREE_OPERAND (new_obj, 0))) == UNION_TYPE
+ && is_really_empty_class (TREE_TYPE (new_obj),
+ /*ignore_vptr*/false))
+ {
+ tree activate = build2 (MODIFY_EXPR, TREE_TYPE (new_obj),
+ new_obj,
+ build_constructor (TREE_TYPE (new_obj),
+ NULL));
+ cxx_eval_constant_expression (ctx, activate, lval,
+ non_constant_p, overflow_p);
+ ggc_free (activate);
+ }
+ }
else if (VOID_TYPE_P (TREE_TYPE (res)))
result = void_node;
else
--- /dev/null
+// PR c++/102163
+// { dg-do compile { target c++11 } }
+
+struct O {
+ constexpr O(int) { }
+};
+
+union _Variadic_union {
+ constexpr _Variadic_union(int __arg) : _M_rest(__arg) { }
+ int _M_first;
+ O _M_rest;
+};
+
+constexpr _Variadic_union u(42);
+
+struct _Variant_storage {
+ constexpr _Variant_storage() : _M_u(42) {}
+ _Variadic_union _M_u;
+};
+
+constexpr _Variant_storage w;