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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 26 15:57:56 UTC 2024


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

          Issue ID: 24724
           Summary: Error when @trusted function returns reference to
                    parameter
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: nick at geany.org

@trusted ref int a(ref int r) { return r; }
@trusted int* b(ref int r) { return &r; }

The above functions violate the @trusted requirement of having a safe
interface, so these should both error on their return statements. The `return`
attribute is a requirement for a safe interface when a `ref` parameter may
escape. Otherwise, those functions should be @system (then no error is needed).

PR incoming.

Note the following are errors even in @system code:

@system ref int c(int r) { return r; }
@system int* d(int r) { return &r; }

--


More information about the Digitalmars-d-bugs mailing list