http://d.puremagic.com/issues/show_bug.cgi?id=5655

           Summary: Lambda inside static foreach saves wrong value of
                    counter
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: and...@metalanguage.com


--- Comment #0 from Andrei Alexandrescu <and...@metalanguage.com> 2011-02-26 
09:25:07 PST ---
This program should print 1 but instead prints 0. Apparently all lambdas inside
a static foreach loop capture 0.

import std.stdio, std.typetuple;

void main() 
{
    TypeTuple!(int, float) TT;
    void function() funs[2];
    foreach (i, T; TT)
    {
        funs[i] = function { writeln(i); };
    }
    funs[1]();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to