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.
Comment #1 by dkorpel — 2023-02-09T10:43:55Z
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 ***
Comment #2 by bugzilla — 2023-02-10T08:57:18Z
This has a simpler test case, so I'm going to fix it and then look at 22916.
Comment #3 by dlang-bot — 2023-02-10T08:59:20Z
@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
Comment #4 by dlang-bot — 2023-02-12T23:30:24Z
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