```d
@nogc:
void foo(alias cb)() {}
void main() {
int x = 0;
foo!(() => x)();
}
```
I would expect the code to compile since the closure is inside an alias.
The code does compile if I change `foo` to `void foo(alias cb)() { cb(); }`.
Comment #1 by andy-hanson — 2019-02-17T20:41:57Z
This error is happening for used callbacks too.
```d
import core.stdc.stdio : printf;
void callThese(cbs...)() {
static foreach (i; 0..cbs.length)
cbs[i]();
}
@nogc:
void main() {
int x = 0;
callThese!(
() {
int y = x;
printf("a\n");
},
() {
printf("b\n");
},
)();
}
```
Removing the `@nogc` and running shows that both are called, but there is still a compile error with `@nogc`:
```
source/app.d(10,6): Error: function `D main` is @nogc yet allocates closures with the GC
source/app.d(13,3): app.main.__lambda1 closes over variable x at source/app.d(11,6)
```
(had to put `callThese` above the `@nogc:` because of https://issues.dlang.org/show_bug.cgi?id=17800 )
Comment #2 by robert.schadek — 2024-12-13T19:02:27Z