[Issue 24208] [DIP1000] Nested function can pass scope pointer to non-scope parameter

2023-10-29 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=24208

Paul Backus  changed:

   What|Removed |Added

Summary|[DIP1000] Nested function   |[DIP1000] Nested function
   |can escape scope parameter  |can pass scope pointer to
   ||non-scope parameter

--


[Issue 24208] [DIP1000] Nested function can pass scope pointer to non-scope parameter

2023-10-29 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=24208

--- Comment #1 from Paul Backus  ---
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();
assert(escaped == );
}
---

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, );
// Error: address of variable `n` assigned to `escaped` 
// with longer lifetime
assert(escaped == );
}
---

--


[Issue 24208] [DIP1000] Nested function can pass scope pointer to non-scope parameter

2023-10-29 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=24208

Paul Backus  changed:

   What|Removed |Added

   Keywords||accepts-invalid, safe

--