[Issue 12808] Small amount of escape analysis to allow more @nogc functions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Dec 8 16:23:42 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=12808
Stanislav Blinov <stanislav.blinov at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |stanislav.blinov at gmail.com
--- Comment #1 from Stanislav Blinov <stanislav.blinov at gmail.com> ---
Rewritten relevant parts into contemprary D. With dmd 2.098:
void program2() @nogc {
foreach (x; [1, 2]) {}
}
import std.array : staticArray;
void program3() @nogc {
import std.algorithm: filter;
foreach (x; [1, 2].filter!(x => true)) {} // fails to infer @nogc
// workaround:
foreach (x; [1, 2].staticArray[].filter!(x => true)) {}
}
int[] program5() @nogc {
return [1, 2].staticArray; // detects the escape correctly
}
void main() {}
So I guess the only outstanding enhancement here is to make this infer @nogc:
foreach (x; [1, 2].filter!(x => true)) {}
...if at all possible. If not, I guess this could be closed?
--
More information about the Digitalmars-d-bugs
mailing list