[Issue 24724] Error when @trusted function returns reference to parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 26 20:20:19 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24724

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel at live.nl
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #6 from Dennis <dkorpel at live.nl> ---
(In reply to Nick Treleaven from comment #4)
> In what scenario is allowing @trusted to have an unsafe interface useful? A
> single example will suffice, please provide one (that can't be @system).

The interface is not necessarily unsafe. The example you gave is trivial, but
the return statement may be unreachable or guarded like so:

```
@trusted int* b(ref int r) 
{ 
    if (isInDataSegment(&r))
        return &r; 
    else
        return null;
}
```

--


More information about the Digitalmars-d-bugs mailing list