C++ Logo

std-proposals

Advanced search

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

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Mon, 2 May 2022 21:50:22 +0100
On Mon, 02 May 2022 12:29:42 -0700
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 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.
>

There is some possibly observable effect due to
https://eel.is/c++draft/expr.call#7.sentence-10 :

"It is implementation-defined whether the lifetime of a parameter ends
when the function in which it is defined returns or at the end of the
enclosing full-expression."

On MSVC the lifetime of the parameter is at the end of the function (it
pretty much has to be, due to its ABI), but AFAIK gcc and clang
destroys function parameters at the end of the enclosing
full-expression.

Cheers,
Lénárd

Received on 2022-05-02 20:50:30