auto ref function parameter causes that non copyable struct is copied?

Stanislav Blinov stanislav.blinov at gmail.com
Tue Nov 9 02:19:28 UTC 2021


On Monday, 8 November 2021 at 23:26:39 UTC, tchaloupka wrote:

> ```
> auto gen() {
>     Foo f;                   // <--- this one
>     f.n = 42;
>     return value(f.move());
> }
>
> void main() {
>     Foo f;
>     f = gen().unwrap.move;
> }
> ```
> ~this(0)
> ~this(0)
> ~this(0)
> ~this(42) <- this is a copy (that shouldn't exist) being 
> destroyed
> ~this(0)
> ~this(42)


Is it a copy? I think the first destructor call is one of `f` in 
`gen` (marked by the comment above)


More information about the Digitalmars-d-learn mailing list