checkedint call removal

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 28 05:08:39 PDT 2014


"John Colvin"  wrote in message news:iguetbdxlyilavlizqry at forum.dlang.org...

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



More information about the Digitalmars-d mailing list