[Issue 17448] Move semantics cause memory corruption and cryptic bugs

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue May 30 09:27:06 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17448

Andrei Alexandrescu <andrei at erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei at erdani.com

--- Comment #8 from Andrei Alexandrescu <andrei at erdani.com> ---
The problem here is the delegate escapes a pointer to a struct. The compiler is
free to move around structs that are manipulated by value, therefore escaping
&this from any struct method is not safe. (Technically the type of `this`
inside a method of struct T is `scope ref T`, not `ref T`.)

Sadly the way to go from here is disallow the code entirely in @safe mode. The
notion that the compiler can freely move around value types is deeply embedded
in the language, and has many benefits. There are no plans to change that.

For data that doesn't change location in memory, dynamic or user-defined
allocation is the go-to solution.

--


More information about the Digitalmars-d-bugs mailing list