[Issue 6141] New: Bad code with ref-foreach and closures

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 10 02:23:10 PDT 2011


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

           Summary: Bad code with ref-foreach and closures
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: thecybershadow at gmail.com


--- Comment #0 from Vladimir Panteleev <thecybershadow at gmail.com> 2011-06-10 02:18:34 PDT ---
void takeADelegate(void delegate()) {}

void main()
{
    auto items = new int[1];
    items[0] = 17;
    foreach (ref item; items)
    {
        // both asserts fail
        assert(item == 17);
        assert(&item == items.ptr);

        takeADelegate({
            auto x = &item;
        });
    }
}

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


More information about the Digitalmars-d-bugs mailing list