assume, assert, enforce, @safe

via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 04:01:54 PDT 2014


On Thursday, 31 July 2014 at 10:24:07 UTC, ponce wrote:
> If I write:
>
> ---
> switch(expr())
> {
> case 0: doIt();
> case 1: doThat();
> default:
>   assert(0);
> }
> ---
>
> Will the optimizer be able to remove the default: case?

Assuming fall-through (`goto case`), not only the default case. 
The entire switch could be removed, under the condition that the 
compiler can prove that neither `expr()`, `doIt()`, nor 
`doThat()` throws, even if they have side effects. And maybe even 
the entire function, and all functions that call it, depending on 
how exactly the control flow is.


More information about the Digitalmars-d mailing list