https://issues.dlang.org/show_bug.cgi?id=14971

          Issue ID: 14971
           Summary: array.length -= x; should be checked for underflow
                    when compiling without -release
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: [email protected]
          Reporter: [email protected]

For exactly the same reason that the index-out-of-bounds runtime checks are
useful for debugging purposes when compiling without the -release flag,
decrements on the array .length attribute should be checked during runtime for
underflow.

As it is now:

int main()
{
    int[] a = [];
    a.length--;
    return 0;
}

Will yield:

core.exception.OutOfMemoryError@(0)

This should instead be an error message along the lines of the
index-out-of-bounds exception that indicates what the problem actually is.

This is related to Issue 3933 from 2010 (there's still no line number on the
error, which goes a long way to making this issue less important).

--

Reply via email to