[Issue 21165] New: Spurious @nogc error with delegate taking `immutable size_t`
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Aug 15 21:47:35 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21165
Issue ID: 21165
Summary: Spurious @nogc error with delegate taking `immutable
size_t`
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: andy.pj.hanson at gmail.com
This particular code fails with a compile error that it shouldn't.
```
@nogc:
void main() {
int x = 0;
f((int, immutable size_t) {
int y = x;
});
}
void f(T)(scope void delegate(T, immutable size_t) @nogc cb) {
cb(0, 0);
}
```
When I run `dmd app.d` this fails with:
```
app.d(3): Error: function D main is @nogc yet allocates closures with the GC
app.d(5): app.main.__lambda1 closes over variable x at app.d(4)
```
There is no compile error if:
* The second delegate parameter is something other than `immutable size_t`
(such as `size_t` or `immutable bool`).
* An explicit type argument is given to `f`, as in `f!int`.
* The delegate parameters are named, as in `f((int a, immutable size_t b) {`.
--
More information about the Digitalmars-d-bugs
mailing list