[Dlang-internal] DIP1000 discussion and testing

Mathias Lang via Dlang-internal dlang-internal at puremagic.com
Wed Nov 23 03:08:31 PST 2016


On Wednesday, 23 November 2016 at 03:35:16 UTC, Walter Bright 
wrote:
> On 11/20/2016 8:41 AM, Mathias Lang wrote:
>> And from a quick test (Using `-dip25 -transition=safe` and 
>> 5928249 which is the
>> commit of this P.R.), the following code:
>>
>> ```
>> void main () @safe
>> {
>>     scope o = new Object();
>> }
>> ```
>>
>> Results in the following error:
>> scope2.d(3): Error: delete o is not @safe but is used in @safe 
>> function main
>>
>> Which works with the compiler I'm currently using, 2.071.2.
>
> This was done here back in June:
>
>   
> https://github.com/dlang/dmd/commit/e64ae1d3e5aa078a036242864a68499617c9b278
>
> and was added to fix:
>
>   https://issues.dlang.org/show_bug.cgi?id=16195
>
> The trouble is, operator delete is not safe.
>
> What do you suggest?

If I understand correctly, it's not @safe because it might free a 
reference which is still used elsewhere, making it dangling.

If we have the correct `scope` enforcement though, we can allow 
it *only at the scope which `new`ed it*, because we know it's not 
possible than any other place has a reference to it, as the 
reference would have to be `scope` as well.

Does that make sense ?


More information about the Dlang-internal mailing list