@safe D requires which DIP switches?

Dukc ajieskola at gmail.com
Sat Jan 8 00:13:38 UTC 2022

On Wednesday, 5 January 2022 at 10:47:50 UTC, Dennis wrote:
> On Wednesday, 5 January 2022 at 10:05:02 UTC, Atila Neves wrote:
>> I talked to Walter about this and I don't think it's the 
>> correct fix. I've been looking at how to do it otherwise.
> Why not? Given a signature like:
> ```D
> int fun(string s) pure nothrow;
> ```
> You can assume `s` is `scope`, because there's no channel to 
> escape it: return value has no pointers, global variables are 
> not accessible in a pure function, there are no other 
> parameters to assign it to.

There is one problem with this. The string could still be 
assigned to a non-`Exception` `Throwable` and thrown. If the 
function implementation is also `@safe`, the compiler is going to 
wrongly prevent throwing the exception due to the automatically 
added `scope`.

When you think of it, it means that `assert`s using `s` as the 
message would be forbidden. Or worse, they would be allowed but 
the assert failure printer would then try to access expired 
memory after such an assert has gone boom.

More information about the Digitalmars-d mailing list