Thread overview
[Issue 7894] New: [CTFE] - goto within ForStatement restarts loop
Apr 12, 2012
dawg@dawgfoto.de
Jul 09, 2012
Don
Jul 14, 2012
Walter Bright
April 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7894

           Summary: [CTFE] - goto within ForStatement restarts loop
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dawg@dawgfoto.de


--- Comment #0 from dawg@dawgfoto.de 2012-04-12 15:25:07 PDT ---
cat > bug.d << CODE
int foo()
{
    foreach(v; 0 .. 2)
    {
        auto n = v;
    Lagain:
        if (n--) goto Lagain;
    }
    return 0;
}

enum ctfe = foo();
CODE

dmd -c bug.d

--------

This will loop endlessly because the loop initializer is reinterpreted after each goto.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7894


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2012-07-09 01:28:00 PDT ---
Slightly reduced test case:

int bug7894()
{
    for (int k = 0; k < 2; ++k) {
        goto Lagain;
Lagain: ;
    }
    return 1;
}
static assert( bug7894() );

Actually the loop initializer isn't reinterpreted after each goto. What's happening is that the increment is skipped.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7894



--- Comment #2 from github-bugzilla@puremagic.com 2012-07-14 13:03:37 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/9d6bc4560c3554b866f4bc8c6ace50b56c091953 Fix issue 7894 [CTFE] - goto within ForStatement restarts loop

Also fixes a very similar bug in do-while loops

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7894


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


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