[Issue 13381] Two cases of array literal that can be stack-allocated
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Oct 31 03:27:14 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13381
--- Comment #15 from bearophile_hugs at eml.cc ---
Another common case where I'd like the compiler to avoid GC-allocations:
void main() @nogc {
immutable int[4] a1 = [1, 2, 4, 5];
size_t i = 2;
immutable int[5] a2 = a1[0 .. i] ~ 3 ~ a1[i .. $];
}
Currently you have to write this more bug-prone code and the 'a2' variable
can't be immutable:
void main() @nogc {
immutable int[4] a1 = [1, 2, 4, 5];
size_t i = 2;
int[5] a2 = void;
a2[0 .. i] = a1[0 .. i];
a2[2] = 3;
a2[i + 1 .. $] = a1[i .. $];
}
--
More information about the Digitalmars-d-bugs
mailing list