The following is a quote from a comment in the Reddit post about asserts that Walter just linked to:

    "Asserts are not without pitfalls, though. If you aren't careful,
     what to put in the asserts, the program could behave differently"

A trivial example of this is:

    int i;
    write(i);
    assert (++i == 1);
    write(i);

Normally, this program prints "01", but in release mode it prints "00". Asserts should never change the behaviour of a program, but currently it is up to the programmer to verify that this is in fact the case.

Would it be possible (and desirable) for the D compiler to statically check that asserts have no side effects?

-Lars

Reply via email to