[Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Oct 2 09:14:00 PDT 2014


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

--- Comment #15 from hsteoh at quickfur.ath.cx ---
P.S., printing out the addresses of local variables outside the loop as well as
the loop counter, reveals that if we comment out the line that initializes the
delegates closing over the loop counter, then the loop counter is allocated on
the stack, but with the closures, the compiler actually allocates the loop
counter on the heap. However, it fails to recognize that multiple iterations of
the loop will reuse the same heap variable.

So it looks like the compiler is already halfway there; it's already detecting
the closure and putting the loop counter on the heap instead of the stack. Now
the only thing that remains, is for it to detect that it needs a new instance
of the loop counter per iteration, as opposed to just a single instance.

--


More information about the Digitalmars-d-bugs mailing list