[Issue 19682] Unused alias causes @nogc error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 17 20:41:57 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19682

--- Comment #1 from andy.pj.hanson at 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 )

--


More information about the Digitalmars-d-bugs mailing list