Bug 19682 – Unused alias causes @nogc error

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-02-17T03:40:07Z
Last change time
2024-12-13T19:02:27Z
Assigned to
No Owner
Creator
andy-hanson
Moved to GitHub: dmd#19540 →

Comments

Comment #0 by andy-hanson — 2019-02-17T03:40:07Z
```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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19540 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB