www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12811] New: GC-allocated closure for calling instance

https://issues.dlang.org/show_bug.cgi?id=12811

          Issue ID: 12811
           Summary: GC-allocated closure for calling instance function in
                    filter
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

I am not sure if it's correct for this code to refuse  nogc:


import std.algorithm: filter;
struct Foo {
    bool bar(in int)  nogc {
        return true;
    }
    auto spam()  nogc {
        immutable static data = [1, 2];
        return data.filter!(i => bar(i));
    }
}
void main() {}


dmd 2.066alpha gives:

temp.d(6,10): Error: function temp.Foo.spam  nogc function allocates a closure
with the GC


This gives a similar error:

import std.algorithm: filter;
struct Foo {
    bool bar(in int)  nogc {
        return true;
    }
    auto spam()  nogc {
        immutable static data = [1, 2];
        scope immutable f = (int i) => bar(i);
        return data.filter!f;
    }
}
void main() {}

--
May 27 2014