For: --- alias VErr = char*; @safe: ref char* front_p(return scope char** p) { return *p; } __gshared char* g; void main() { char* _errors; g = front_p(&_errors); // Error: address of variable `_errors` assigned to `g` with longer lifetime } --- The error is incorrect. The return value is indirected before assignment to `g`, so the address of `_errors` isn't being assigned to `g`, what `_errors` is pointing to is assigned to `g`. This can be seen by commenting out `@safe:`, compiling it, and looking at the assembler.
Lol, when I posted this, you tried to convince me it's working as intended and closed as invalid. I'm glad we're on the same page now. *** This issue has been marked as a duplicate of issue 22916 ***
This has a simpler test case, so I'm going to fix it and then look at 22916.
@WalterBright created dlang/dmd pull request #14869 "fix Issue 23682 - dip1000 problem with return by ref" fixing this issue: - fix Issue 23682 - dip1000 problem with return by ref https://github.com/dlang/dmd/pull/14869
dlang/dmd pull request #14869 "fix Issue 23682 - dip1000 problem with return by ref" was merged into master: - 2b12d6fe9e704a6807101f17bca5fa7e63bdcb78 by Walter Bright: fix Issue 23682 - dip1000 problem with return by ref https://github.com/dlang/dmd/pull/14869