August 26 [Issue 24724] New: Error when @trusted function returns reference to parameter | ||||
---|---|---|---|---|
| ||||
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@puremagic.com Reporter: nick@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; } -- |
Copyright © 1999-2021 by the D Language Foundation