[Issue 2678] New: for loops are already assumed to terminate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 20 07:15:40 PST 2009


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

           Summary: for loops are already assumed to terminate
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: andrei at metalanguage.com


Consider this code compiled with -w:

int main()
{
    int i;
    for (;; ++i)
    {
        if (i == 10) return 0;
    }
    i += 100;
}

This loop never reaches its end. However the compiler does not detect that and
spuriously asks for a return at the end of the function. Worse, if there is
some unreachable code following the loop, it does not recognize that.

All loops that (a) have no termination condition or a nonzero
compile-time-constant termination condition, and (b) do not embed any "break"
statement - should be understood as loops that do not fall through.

Before anyone brings up Turing completeness: I said "nonzero
compile-time-constant termination condition".


-- 



More information about the Digitalmars-d-bugs mailing list