Struct should be invalid after move
Steven Schveighoffer
schveiguy at gmail.com
Wed Nov 28 19:11:14 UTC 2018
On 11/28/18 1:59 PM, Neia Neutuladh wrote:
> On Wed, 28 Nov 2018 12:47:07 -0500, Steven Schveighoffer wrote:
>> But in any case, this doesn't fix all the problems anyway, you could
>> have another alias to the same data, free that alias, and then ptr1 is
>> still "valid".
>
> Move constructors and init'ing out the moved variable address that, no?
>
Not sure what you mean. What I'm talking about is this:
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.
-Steve
More information about the Digitalmars-d
mailing list