Bug 23204 – [REG2.097] discarded scope return still allocates GC closure

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-06-22T09:37:00Z
Last change time
2024-12-13T19:23:33Z
Keywords
industry, rejects-valid
Assigned to
No Owner
Creator
johanengelen
Moved to GitHub: dmd#20124 →

Comments

Comment #0 by johanengelen — 2022-06-22T09:37:00Z
Testcase: ``` auto invoker(Dlg)(scope Dlg dlg) { return dlg; } // <--- `return` is inferred on parameter // Does not compile, but should. @nogc void f(int x) { invoker({x++;}); } // <--- return value is discarded, hence does not escape the scope. // This compiles fine, without gc allocation: @nogc void g(int x) { scope inv = invoker({x++;}); inv(); } ``` Compilation succeeds with 2.096, fails with 2.097 with the error: <source>(3): Error: function `example.f` is `@nogc` yet allocates closures with the GC <source>(3): example.f.__lambda2 closes over variable x at <source>(3) C The regression is related to the fix for https://issues.dlang.org/show_bug.cgi?id=21912
Comment #1 by robert.schadek — 2024-12-13T19:23:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20124 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB