[Issue 13702] New: One missed 'may cause GC allocation' error message
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Sat Nov  8 05:31:36 PST 2014
    
    
  
https://issues.dlang.org/show_bug.cgi?id=13702
          Issue ID: 13702
           Summary: One missed 'may cause GC allocation' error message
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: bearophile_hugs at eml.cc
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
--
    
    
More information about the Digitalmars-d-bugs
mailing list