Bug 13702 – One missed 'may cause GC allocation' error message
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-11-08T13:31:00Z
Last change time
2016-02-02T02:04:37Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2014-11-08T13:31:36Z
This program contains two similar functions, both contain two cases of GC allocations, but in 'bar' the D compiler misses one of them (it catches it later if you remove the first GC allocation inside 'bar'):
int[] foo(bool b) @nogc {
if (b)
return [1];
return 1 ~ [2];
}
int[] bar(bool b) @nogc {
if (b)
return [1];
auto aux = 1 ~ [2];
return aux;
}
void main() {}
DMD 2.067alpha gives:
test.d(3,16): Error: array literal in @nogc function foo may cause GC allocation
test.d(4,16): Error: array literal in @nogc function foo may cause GC allocation
test.d(9,20): Error: array literal in @nogc function bar may cause GC allocation