One case of GC-allocated closure

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 26 14:59:13 PDT 2014


I don't know if this is a bug, an enhancement request, or just a 
mistake of mine. I don't understand why currently @nogc refuses 
this code:


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


dmd 2.066alpha gives:

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

Is this a bug/ER worth reporting?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list