Two bugs found: GC bug as well as scope delegate bug

Mehrdad wfunction at hotmail.com
Sat Aug 6 21:42:42 PDT 2011


Something always told me the I can't trust D's GC, the way the working 
set always grew (even though people always claimed that's not a good 
measure of anything)... now I think I finally have proof. :)

I believe I've found at least two behaviors, neither of which should happen:

1. I should NOT get an OutOfMemory error.
2. There should NOT be a GC allocation anywhere in the first place -- 
everything is well-scoped, and I've used the 'scope' modifier.
3. If the compiler isn't respecting 'scope' on a parameter, it should 
IMHO give at _least_ a warning (if not an error, which would be more 
desirable).

Code:

         void enumerate(T)(T[] items, scope void delegate(T) sink)  // 
I've said 'scope', but the compiler doesn't respect it.
         {
                 foreach (item; items)
                         sink(item);
         }

         struct Temp(T)
         {
                 T[] buf;
                 void test(T[] items)
                 {
                         for (;;)
                                 enumerate(items, delegate(T item) { 
this.buf ~= item; });  //The compiler thinks that the scope of this.buf 
is escaped, but it's not
                 }
         }

         void main()
         {
                 int[10] buf;
                 Temp!int().test(buf);
         }

I ran this on a nightly pull of DMD 2.054 (perhaps the bugs have been 
fixed?). When I run this, the program crashs with an out of memory error 
(after allocating around a gigabyte of RAM).

Are these actually 2-3 bugs, or am I missing something?


More information about the Digitalmars-d mailing list