[Issue 3154] New: foreach corrupting data returned by ref functions.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 8 13:43:13 PDT 2009


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

           Summary: foreach corrupting data returned by ref functions.
           Product: D
           Version: 2.031
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: kovrov+puremagic at gmail.com


void main()
{
    auto test = Foo(3);
    foreach (i; test.items) { }
}

struct Foo
{
    struct Generator
    {
        int opApply(int delegate(ref long) dg)
        {
            const bak = this.foo.data;  // control copy
            int res;
            for (long i=0; i < bak; i++)
            {
                assert (bak == this.foo.data, "this.foo changed?!");
                res = dg(i);
                if (res)
                    break;
            }
            return res;
        }
        Foo foo;
    }
    ref Generator items() // ref is important
    {
        return Generator(this); // Generator.foo = this
    }
    int data;
}

-- 
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