[Issue 24208] [DIP1000] Nested function can pass scope pointer to non-scope parameter
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Oct 29 23:01:57 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24208
--- Comment #1 from Paul Backus <snarwin+bugzilla at gmail.com> ---
Actually, it turns out the second function is not necessary:
---
void main() @safe
{
int* escaped;
void escape(int* p) @safe
{
escaped = p;
}
int n;
escape(&n);
assert(escaped == &n);
}
---
So, I guess the problem is either that the compiler is incorrectly inferring
`p` as `return scope`, or it's *correctly* inferring `p` as `return scope` but
failing to notice at the calls site that the "return value" has a longer
lifetime than `n`.
If it's the second case, the error should be the same one produced by this
program:
---
void main() @safe
{
int* escaped;
static void escape(ref int* ret, return scope int* p) @safe
{
ret = p;
}
int n;
escape(escaped, &n);
// Error: address of variable `n` assigned to `escaped`
// with longer lifetime
assert(escaped == &n);
}
---
--
More information about the Digitalmars-d-bugs
mailing list