aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-09-17 08:46:39 -0700
committerIan Lance Taylor <iant@golang.org>2021-09-17 08:46:39 -0700
commita0791d0ed4f147ef347e83f4aedc7ad03f1a2008 (patch)
tree7b3526910798e4cff7a7200d684383046bac6225 /gcc/cp/constexpr.c
parente252b51ccde010cbd2a146485d8045103cd99533 (diff)
parent89be17a1b231ade643f28fbe616d53377e069da8 (diff)
downloadgcc-a0791d0ed4f147ef347e83f4aedc7ad03f1a2008.zip
gcc-a0791d0ed4f147ef347e83f4aedc7ad03f1a2008.tar.gz
gcc-a0791d0ed4f147ef347e83f4aedc7ad03f1a2008.tar.bz2
Merge from trunk revision 89be17a1b231ade643f28fbe616d53377e069da8.
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r--gcc/cp/constexpr.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 0c2498a..8a5dd06 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -2787,12 +2787,34 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
&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
@@ -7480,8 +7502,7 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
/* Remember the original location if that wouldn't need a wrapper. */
if (location_t loc = EXPR_LOCATION (t))
- if (CAN_HAVE_LOCATION_P (r))
- SET_EXPR_LOCATION (r, loc);
+ protected_set_expr_location (r, loc);
return r;
}