Bug 23667 – [REG2.101] Incorrect escape deprecation on scope lazy pointer parameter

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-02-02T22:20:02Z
Last change time
2024-12-13T19:27:06Z
Keywords
industry, rejects-valid
Assigned to
No Owner
Creator
johanengelen
Moved to GitHub: dmd#20225 →

Comments

Comment #0 by johanengelen — 2023-02-02T22:20:02Z
Testcase: ``` struct S { this(ref int i) { DBG(&i); } } void DBG(lazy scope int* args) {} ``` Compilation with dlang2.101 gives the error: <source>(3): Deprecation: escaping reference to outer local variable `i` Removing `lazy` makes the code compile. Note that this is very similar but distinct from https://issues.dlang.org/show_bug.cgi?id=21290 , because that regression already appeared from 2.073.
Comment #1 by razvan.nitu1305 — 2023-02-03T10:53:20Z
The compiler essentially rewrites the code to: ``` struct S { this(ref int i) { DBG(() => &i); } } void DBG(scope int* delegate() args) {} ``` So it essentially attaches scope to args no to the return type of args (as far as I understand it doesn't make sense to attach scope on a return type), therefore the scoping information is lost and the compiler is conservative and doesn't let you do that. I guess the compiler should first perform escape analysis before lowering i to a delegate.
Comment #2 by razvan.nitu1305 — 2023-02-03T12:18:47Z
Actually, it turns out you can escape i: struct S { this(ref int i) { DBG(&i); } } int* delegate() outer; void DBG(lazy scope int* args) { outer = &args; } void main() { int b; S s = S(b); import std.stdio; writeln(*outer()); } It seems that scope is not propagated on the extracted delegate.
Comment #3 by robert.schadek — 2024-12-13T19:27:06Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20225 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB