Surprise destructor call...
Manu
turkeyman at gmail.com
Wed Aug 14 14:41:37 UTC 2024
On Thu, 15 Aug 2024 at 00:31, kinke via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:
> On Wednesday, 14 August 2024 at 13:56:08 UTC, Manu wrote:
> > Well, the condition is that NRVO should elide the copy/move...
> > it should be
> > constructed at the caller's scope in this case.
> > Your example `Thing(null).field` is not the same thing, because
> > it's not
> > NRVO at all.
> >
> > I guess this is a bug then?
>
> When actually using NRVO (`auto r = Thing(null); return r;`), one
> even gets the error *twice*. So that's definitely a bug, the
> destruction is handled by the caller; just for the attributes
> check etc., there's no real dtor call in `fun()`.
>
> What you have is a case for RVO; AFAIK, LDC and GDC implement
> that (for non-POD types at least), no idea about DMD. Meaning
> that the temporary in the return expression isn't destructed by
> `foo` either; it's emplaced directly into the caller-allocated
> return value, as the NRVO case.
>
My understanding is that RVO is in the D spec and NOT simply an
optimisation. The language shouldn't attempt to call a destructor here in
my case under any circumstances...
Walter?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20240815/e6e210c6/attachment.htm>
More information about the Digitalmars-d
mailing list