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