Returning a reference to be manipulated

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sat Apr 15 13:24:52 UTC 2023


On 16/04/2023 1:20 AM, kdevel wrote:
> On Saturday, 15 April 2023 at 12:45:31 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
>> It was bad analysis by the compiler, which has since been corrected.
>>
>> It should have been applied only to @safe code.
> 
> But why is the @unsafe programmer now left unprotected in cases like this
> 
> ```
> ref int foo (ref int i)
> //           `------- automatically insert `return` here?
> {
>     return i;
> }
> ```
> 
> where the compiler recognizes that the function returns a ref parameter?
> 
> Under which circumstances is it a mistake to insert the `return` at the 
> indicated position? If there are none why can't it be done implicitly 
> (automatically)?

@system (which is currently the default, there is a strong desire to 
change this), does no safety checks.

You are on your own to do whatever unsafe thing you want.

If you want safety checks, use @safe.


More information about the Digitalmars-d-learn mailing list