https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104055

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Because of the consteval build_over_call will do:
9920              if (obj_arg && is_dummy_object (obj_arg))
9921                {
9922                  call = build_cplus_new (DECL_CONTEXT (fndecl), call,
complain);
9923                  obj_arg = NULL_TREE;
9924                }
where the build_cplus_new creates a TARGET_EXPR with TARGET_EXPR_CLEANUP of
A::~A (&temp) on it.
But then it calls
9938              call = cxx_constant_value (call, obj_arg);
and cxx_constant_value triggers:
7818      if (TREE_CODE (r) == CONSTRUCTOR && CLASS_TYPE_P (TREE_TYPE (r)))
7819        {
7820          r = adjust_temp_type (type, r);
7821          if (TREE_CODE (t) == TARGET_EXPR
7822              && TARGET_EXPR_INITIAL (t) == r)
7823            return t;
7824          else if (TREE_CODE (t) != CONSTRUCTOR)
7825            {
7826              r = get_target_expr_sfinae (r, tf_warning_or_error |
tf_no_cleanup);
7827              TREE_CONSTANT (r) = true;
7828            }
7829        }
where it creates a new TARGET_EXPR but this time without TARGET_EXPR_CLEANUP
because of the tf_no_cleanup and that is what is returned.
I've tried to copy TARGET_EXPR_CLEANUP from t to r either in the above
constexpr.c spot, or in build_over_call, but neither worked as the cleanup
refers to a different slot.  Now, I think the initializer shouldn't be refering
to the slot decl (e.g. take its address), because that wouldn't be a constant
expression.

Reply via email to