https://issues.dlang.org/show_bug.cgi?id=22680
ag0aep6g <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |safe CC| |[email protected] Severity|enhancement |minor --- Comment #2 from ag0aep6g <[email protected]> --- (In reply to RazvanN from comment #1) > There is nothing unsafe in assigning a class reference to another. Unless you're assigning garbage, which is happening here. A more elaborate demonstration of the unsafety: ---- import std.stdio: writeln; import core.memory: GC; C c; class C { immutable int* ip; this(int x) @safe { this.ip = new int(x); } ~this() @safe { c = this; } } void main() @safe { () { new C(42); } (); () { ubyte[1000] clear_stack; } (); () @trusted { GC.collect(); } (); immutable int* ip = c.ip; writeln(*ip); /* Prints "42". */ new int(13); int should_still_be_42 = *ip; writeln(should_still_be_42); /* Prints "13" - immutable data has changed. */ } ---- --
