On Tuesday, 9 November 2021 at 02:19:28 UTC, Stanislav Blinov
wrote:
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)
The expectation is probably that `f.move` set `f` to `Foo.init`,
but the docs say:
"If T is a struct with a destructor or postblit defined, source
is reset to its .init value after it is moved into target,
otherwise it is left unchanged."
```d
struct A { int x; }
struct B { int x; this(this) { } }
unittest {
import core.lifetime : move;
auto a = A(5);
auto b = B(5);
a.move;
b.move;
assert(a == A(5));
assert(b == B(0));
}
```