Struct delegate access corruption
kinke
noone at nowhere.com
Thu Feb 18 08:29:48 UTC 2021
On Wednesday, 17 February 2021 at 20:44:46 UTC, tsbockman wrote:
> On Wednesday, 17 February 2021 at 20:18:53 UTC, Paul Backus
> wrote:
>> On Wednesday, 17 February 2021 at 19:42:00 UTC, tsbockman
>> wrote:
>>> A copy constructor and opAssign can be used to update
>>> pointers that are relative to &this:
>>> https://dlang.org/spec/struct.html#struct-copy-constructor
>>
>> Unfortunately this is not enough, because the compiler is free
>> to implicitly move struct instances in memory any time it
>> wants to. See the bug report below for more details:
>>
>> https://issues.dlang.org/show_bug.cgi?id=17448
>>
>> Until D gets move constructors, structs with interior pointers
>> should be avoided.
>
> That bug is about postblits, this(this), not copy constructors:
> this(ref typeof(this)). Copy constructors were added to the
> language specifically to fix those sort of problems.
Nope, Paul is right, the copy ctors don't solve anything in this
regard. Simplest example I could come up with:
https://run.dlang.io/is/TgxyU3
More information about the Digitalmars-d-learn
mailing list