C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Relocation in C++

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Mon, 2 May 2022 20:36:39 +0100
On Mon, 2 May 2022 at 20:29, Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Monday, 2 May 2022 12:15:00 PDT Lénárd Szolnoki via Std-Proposals wrote:
> > I'm pretty sure in MSVC parameters are destroyed by the callee. I don't
> > think that this is non-conforming.
> >
> > https://godbolt.org/z/9soos71ae
>
> I stand corrected.
>
> You're right, from the language's point of view it makes no difference
> whether
> the destruction happens before the RET instruction or after (that's not
> observable in the abstract machine), so long as the ordering of
> destruction
> remains consistent. That is, if the two objects x and y in
>
> foo(x, y);
>
> are destroyed in the right order, regardless of who does it.
>

I don't believe there is a "right order". Certainly the order of
initialization of (the parameters initialized by) x and y is indeterminate,
so I imagine their destruction would be indeterminate as well.

Note that, importantly, in

foo(x, y), z

the order of destruction of x and y relative to the evaluation of z is
implementation-defined; they may be destroyed immediately on return or at
the end of the full-expression.


> I was thinking that there could be some side-effects that only the caller
> would know about and that it would require that the caller destroy it, but
> on
> second thought I can't think of any.
>

No, I'm fairly sure this is about access control. (That is, you must be
able to destroy a parameter to call a function, even if the ABI is
callee-destroy.)

Received on 2022-05-02 19:36:52