Returning a reference to be manipulated

kdevel kdevel at vogtner.de
Sat Apr 15 14:33:52 UTC 2023


On Saturday, 15 April 2023 at 14:10:57 UTC, Dennis wrote:
> [...]
> This adds complexity, just to add some 'intermediate' safety 
> between `@system` and `@safe` in a few cases. It's better to 
> keep the rules simple and consistent.

Thanks for the answer! While playing around with return ref I 
came across this:

```
string foo (string s, return ref int i)
{
    return s;
}

auto bar ()
{
    int i;
    string s;
    return foo (s, i);
}
```

```
$ dmd rr.d
rr.d(10): Error: returning `foo(s, i)` escapes a reference to 
local variable `i`
```

Does that make sense?


More information about the Digitalmars-d-learn mailing list