www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13702] New: One missed 'may cause GC allocation' error message

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 puremagic.com
          Reporter: bearophile_hugs 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

--
Nov 08 2014