[Issue 19682] Unused alias causes @nogc error

2022-12-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19682

Iain Buclaw  changed:

   What|Removed |Added

   Priority|P1  |P3

--


[Issue 19682] Unused alias causes @nogc error

2019-02-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19682

--- Comment #1 from andy.pj.han...@gmail.com ---
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 )

--