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

           Summary: destructor is called on 'for' loop variable even when
                    initialization failed
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: [email protected]
        ReportedBy: [email protected]
            Blocks: 10463


--- Comment #0 from Nils <[email protected]> 2013-06-26 02:05:11 PDT 
---
This is reduced from issue 10463.

struct DirIterator
{
    int _store = 42;
    ~this() {assert(_store == 42);} // line 4
}

DirIterator dirEntries()
{
    throw new Exception(""); // line 9
}

void main()
{
    /* This triggers only line 9: */
    version(A) DirIterator a = dirEntries();

    /* This triggers both lines 9 and 4: */
    else version(B)
    {
        DirIterator b = void;
        b = dirEntries();
    }

    /* With 'for' it looks like A, but behaves like B: */
    else for(DirIterator c = dirEntries(); true;) {}
}

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

Reply via email to