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

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


Reply via email to