[Issue 12811] New: GC-allocated closure for calling instance function in filter

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue May 27 04:22:43 PDT 2014


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 at puremagic.com
          Reporter: bearophile_hugs at 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() {}

--


More information about the Digitalmars-d-bugs mailing list