[Issue 12642] New: Avoid some heap allocation cases for fixed-size arrays
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Apr 25 03:46:44 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12642
Issue ID: 12642
Summary: Avoid some heap allocation cases for fixed-size arrays
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: bearophile_hugs at eml.cc
The @nogc annotation of dmd 2.066alpha refuses the following programs:
__gshared int[1] data1;
int[1] bar() @nogc {
int x;
return [x];
}
void main() @nogc {
int x;
data1 = [x];
int[1] data2;
data2 = [x];
}
test.d(4,12): Error: array literals in @nogc function bar may cause GC
allocation
test.d(8,13): Error: array literals in @nogc function main may cause GC
allocation
test.d(10,13): Error: array literals in @nogc function main may cause GC
allocation
But is it possible to avoid heap allocations in those cases, to allow those
programs to compile?
This similar code compiles:
__gshared int[1] data1;
int[1] bar() @nogc {
int x;
typeof(return) tmp;
tmp[0] = x;
return tmp;
}
void main() @nogc {
int x;
data1[0] = x;
int[1] data2;
data2[0] = x;
}
--
More information about the Digitalmars-d-bugs
mailing list