Bug 24256 – `-preview=in` should allow array literals and delegate literals in a `@nogc` context

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-11-23T07:30:43Z
Last change time
2024-12-13T19:31:58Z
Assigned to
No Owner
Creator
Georgy Markov
Moved to GitHub: dmd#20363 →

Comments

Comment #0 by ogion.art — 2023-11-23T07:30:43Z
DMD allows passing array literals and delegate literals to `scope` parameters in @nogc functions: void foo(const scope int[]) @nogc {} void bar(scope void delegate()) @nogc {} void main() @nogc { foo([1, 2, 3]); int x; bar(() { x++; }); } I expect this to work with `in` parameters as well, since “input parameters behave as if they have the `const scope` storage classes” according to spec. But as of DMD v2.105.3 this fails to compile (`-preview=in` enabled): void foo(in int[]) @nogc {} void bar(in void delegate()) @nogc {} void main() @nogc { foo([1, 2, 3]); int x; bar(() { x++; }); } app.d(4): Error: array literal in `@nogc` function `D main` may cause a GC allocation app.d(3): Error: function `D main` is `@nogc` yet allocates closure for `main()` with the GC app.d(6): `app.main.__lambda2` closes over variable `x` at app.d(5)
Comment #1 by nick — 2024-08-16T20:22:04Z
Maybe it doesn't because of issue 23175.
Comment #2 by robert.schadek — 2024-12-13T19:31:58Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20363 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB