Struct should be invalid after move
Steven Schveighoffer
schveiguy at gmail.com
Wed Nov 28 17:47:07 UTC 2018
On 11/28/18 11:49 AM, Atila Neves wrote:
> On Wednesday, 28 November 2018 at 09:17:39 UTC, sanjayss wrote:
>> On Tuesday, 27 November 2018 at 08:00:22 UTC, Sebastiaan Koppe wrote:
>>> [...]
>>
>> I have always wanted a feature in C that would let me explicitly tell
>> the compiler that a variable is no longer in scope (some sort of unset
>> of a variable). This would be useful to do defensive programming
>> against use-after-free of pointers to allocated memory and such.
>
>
> {
> void* ptr = malloc(5);
> }
>
> // ptr no longer in scope
>
I think what the request is that you have variables with overlapping scope.
For example:
void *ptr1 = malloc(5);
void *ptr2 = malloc(5);
...
free(ptr1); // end ptr1 scope
...
free(ptr2); // end ptr2 scope
Which isn't possible by adding a nested scope.
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".
-Steve
More information about the Digitalmars-d
mailing list