Comment #0 by default_357-line — 2022-07-11T09:31:38Z
Consider this code:
import std.stdio;
@safe:
void main() {
auto value = make;
writefln!"field is at %s"(&value.field);
value.field = 5;
assert(value.dg() == 5);
}
Test make() {
return Test(0);
}
struct Test
{
int field;
int delegate() dg;
@disable this(this);
@disable this(ref Test);
this(int) scope {
this.dg = {
writefln!"get field at %s"(&this.field);
return this.field;
};
}
~this() { writefln!"Now destroyed."; }
}
Struct Test has forbidden any form of copying or moving via `@disable this`. We'd assume that either NRVO and inlining would let the constructor be called with `this` at the final location in `with (make)` in main, or some part of this would error. However, even with -dip1000 in master (v2.100.0-8763-gcdfadf8a18), the compiler calls `this(int)` with a different address than `value` in main, and never tries to call postblit or the copy constructor. As a result, the assert fails.
Comment #1 by robert.schadek — 2024-12-13T19:23:47Z