On 1/18/22 09:26, Jakub Jelinek wrote:
On Tue, Jan 18, 2022 at 09:08:03AM -0500, Jason Merrill wrote:
which makes call a TARGET_EXPR with the dtor in TARGET_EXPR_CLEANUP,
but then call cxx_constant_value on it.  In cxx_eval_outermost_constant_expr
it triggers the:
        else if (TREE_CODE (t) != CONSTRUCTOR)
          {
            r = get_target_expr_sfinae (r, tf_warning_or_error | tf_no_cleanup);
            TREE_CONSTANT (r) = true;
          }
which wraps the CONSTRUCTOR r into a new TARGET_EXPR, but one without
dtors (I think we need e.g. the TREE_CONSTANT for the callers),
and finally build_over_call uses that.

Looks like you added the tf_no_cleanup in r10-3661 (constexpr new). Maybe
that should only be added if TARGET_EXPR_CLEANUP (t) is null?

I thought about that, but I'm worried that if the cleanup action
is non-empty, then the TREE_CONSTANT (r) = true; after it isn't appropriate,
because the TARGET_EXPR has side-effects.

Hmm. If we e.g. pull out a subobject value from the TARGET_EXPR temporary, we still need to run the cleanup, so we don't want to optimize the temporary away, so not setting TREE_CONSTANT sounds right.

And the callers like cxx_constant_value_sfinae just return error_mark_node
if it isn't set:
   if (sfinae && !TREE_CONSTANT (r))
     r = error_mark_node;

Yes. Is that wrong? I guess we need to be more careful about adjusting the arguments to cxx_constant_value_sfinae if we still want a constant value.

Perhaps we also still want to set tf_no_cleanup if object is nonnull, since in that case we know the prvalue is going to be an initializer rather than a temporary.

Jason

Reply via email to