Bug 19993 – Reference to delegate after return statement causes unnecessary closure allocation

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-06-22T12:12:38Z
Last change time
2024-12-13T19:04:15Z
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: dmd#17912 →

Comments

Comment #0 by snarwin+bugzilla — 2019-06-22T12:12:38Z
auto call(alias dg)() { return dg(); pragma(msg, typeof(dg)); } @nogc void main() { int acc = 0; call!(() => acc += 1); } --- The program above fails to compile with the following error: Error: function `D main` is @nogc yet allocates closures with the GC However, if the pragma(msg) is moved before the return statement in `call`, there is no error.
Comment #1 by snarwin+bugzilla — 2019-09-29T20:15:48Z
This also affects delegates passed as arguments to template sequence parameters. A reference to a different, non-delegate element of the same sequence parameter can cause a closure to be allocated, as in the following example: --- auto call(Args...)() { return Args[0](); pragma(msg, typeof(Args[1])); } @nogc void main() { int acc = 0; call!(() => acc += 1, "hello"); } --- As before, if the pragma(msg) is moved before the return statement in `call`, the program compiles and runs without error.
Comment #2 by robert.schadek — 2024-12-13T19:04:15Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17912 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB