You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<source>(1): Error: function `example.test` is `@nogc` yet allocates closure for `test()` with the GC
auto test(int a) @nogc
^
<source>(4): delegate `() => a` closes over variable `a`
enum yes = __traits(compiles, { return a; });
^
<source>(1): `a` declared here
auto test(int a) @nogc
^
... but if I comment out either line (1) or line (2) it works fine. It also seems to be important that both foo and a closure in __trait(compiles) close over the same variable.
It's probably expected, but also worth mentioning that it's not just static analysis, codegen is also affected. If I remove @nogc from test declaration, the code compiles, but it does call _d_allocmemory, while commenting either line (1) or line (2) makes it work without memory allocation.
Here is an example:
This produces an error:
... but if I comment out either line (1) or line (2) it works fine. It also seems to be important that both
foo
and a closure in__trait(compiles)
close over the same variable.It's probably expected, but also worth mentioning that it's not just static analysis, codegen is also affected. If I remove
@nogc
fromtest
declaration, the code compiles, but it does call_d_allocmemory
, while commenting either line (1) or line (2) makes it work without memory allocation.The example in godbolt: https://godbolt.org/z/Wzaq1Tzo7
Kudos to @EyalIO for spotting the bug and to @ljmf00 for making a minimal example.
The text was updated successfully, but these errors were encountered: