C++ Logo

std-proposals

Advanced search

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

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Thu, 19 May 2022 09:52:22 -0400
On Thu, 19 May 2022 at 09:41, Sebastian Wittmeier <
wittmeier_at_[hidden]> wrote:

> Hi Edward,
>
> why do we need a temporary in those cases?
>
> Why not elide to just destroy? As is the case for other codepaths (e.g.
> after the else branch, for relocate in the if branch).
>
If the object being relocated is a function parameter, and it has to be
relocated by move+destroy, then it can't be destroyed until the function
terminates since the ABI may be caller-destroy. This is the same with the
other uses of relocate operator; we can't break ABI for calling a function
from code compiled under the previous (i.e. current) version of the
language. Only if the type has relocate operator either defaulted or
user-defined, then the type doesn't support the old ABI, so we can mandate
that callers deal with the argument being relocated from ending its
lifetime during the function, so also it can be destroyed within the
function. (Or if the type is trivial, but then the destructor has no
visible effect.)

Received on 2022-05-19 13:52:34