Struct should be invalid after move

Stanislav Blinov stanislav.blinov at gmail.com
Wed Nov 28 19:27:09 UTC 2018


On Wednesday, 28 November 2018 at 19:11:14 UTC, Steven 
Schveighoffer wrote:

> int *ptr1 = (int *)malloc(sizeof(int));
> int *ptr2 = ptr1;
>
> free(ptr2);
>
> *ptr1 = 5;
>
> If we have a hypothetical C compiler that prevents use of ptr2 
> after free, it probably doesn't know about the link to ptr1, to 
> make that also unusable.
>
> Indeed the runtime solution is much more possible.


For that (or rather, to prevent that) we have non-copyable types. 
Like the one in the OP.


More information about the Digitalmars-d mailing list