On Tue, Dec 08, 2020 at 05:34:13PM -0500, Jason Merrill wrote:
> On 12/8/20 4:23 AM, Jakub Jelinek wrote:
> > The earlier cases in build_new_1 already use | tf_no_cleanup, these are
> > cases where the type isn't type_build_ctor_call nor explicit_value_init_p.
> > It is true that often one can't delete these (unless e.g. the dtor would be
> > private or protected and deletion done in some method), but diagnosing that
> > belongs to delete, not new.
> > 
> > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> > trunk?
> 
> It wasn't clear to me why adding tf_no_cleanup in those places made a
> difference; after some investigation I tried moving the tf_no_cleanup closer
> to where we build a TARGET_EXPR and then soon put it in an INIT_EXPR.

I'm afraid I don't know the FE enough to know.
I see cp_build_modify_expr can be called with INIT_EXPR from
perform_member_init, this build_new_1 case and get_temp_regvar.
Whether it is ok for all of them not to build destructors is something I
have no idea about, for build_new_1 case I was confident it shouldn't be
built.

> I also added an array-new to the testcase.

I thought I should look at the array new case too, but didn't get to that,
sorry.

> diff --git a/gcc/cp/init.c b/gcc/cp/init.c
> index 0b98f338feb..3c3e05d9b21 100644
> --- a/gcc/cp/init.c
> +++ b/gcc/cp/init.c
> @@ -1922,7 +1922,7 @@ expand_default_init (tree binfo, tree true_exp, tree 
> exp, tree init, int flags,
>          in an exception region.  */;
>        else
>       init = ocp_convert (type, init, CONV_IMPLICIT|CONV_FORCE_TEMP,
> -                         flags, complain);
> +                         flags, complain | tf_no_cleanup);
>  
>        if (TREE_CODE (init) == MUST_NOT_THROW_EXPR)
>       /* We need to protect the initialization of a catch parm with a
> diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
> index 4d499af5ccb..afbb8ef02e6 100644
> --- a/gcc/cp/typeck.c
> +++ b/gcc/cp/typeck.c
> @@ -8860,7 +8860,7 @@ cp_build_modify_expr (location_t loc, tree lhs, enum 
> tree_code modifycode,
>         LOOKUP_ONLYCONVERTING.  */
>      newrhs = convert_for_initialization (lhs, olhstype, newrhs, 
> LOOKUP_NORMAL,
>                                        ICR_INIT, NULL_TREE, 0,
> -                                         complain);
> +                                      complain | tf_no_cleanup);
>    else
>      newrhs = convert_for_assignment (olhstype, newrhs, ICR_ASSIGN,
>                                    NULL_TREE, 0, complain, LOOKUP_IMPLICIT);

        Jakub

Reply via email to