[Issue 24256] New: `-preview=in` should allow array literals and delegate literals in a `@nogc` context
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 23 07:30:43 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24256
Issue ID: 24256
Summary: `-preview=in` should allow array literals and delegate
literals in a `@nogc` context
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ogion.art at gmail.com
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)
--
More information about the Digitalmars-d-bugs
mailing list