@safe D requires which DIP switches?

Atila Neves atila.neves at gmail.com
Fri Jan 7 08:39:25 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.
>
> But when the signature is this:
> ```D
> int fun(string s) pure;
> ```
> You can assign `s` to an Exception that gets thrown. How would 
> you prevent / detect that?

You *can*, but it's likely that the vast majority of code 
*won't*. Changing this would break a lot of code, as seen by your 
attempts to fix Phobos.

Another option is making it so pure functions can't throw, but 
that also probably introduces a lot of breakage.


More information about the Digitalmars-d mailing list