"John Colvin" wrote in message news:[email protected]...
To what extent can a compiler use assertions? Can it work backwards from
an assert to affect previous code?
void foo(int a)
{
enforce(a & 1);
assert(a & 1);
}
The assert is dead code, because it will never be reached if (a & 1) is
false.
void bar()
{
assert(a & 1);
enforce(a & 1);
}
The throw inside enforce is dead code, because it will never be reached if
(a & 1) is false.
The compiler is free to remove dead code, because it doesn't change the
program's behaviour.