checkedint call removal

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 01:36:11 PDT 2014


On Thursday, 31 July 2014 at 08:23:44 UTC, Daniel Murphy wrote:
> "Daniel Murphy"  wrote in message 
> news:lrct2d$1me8$1 at digitalmars.com...
>
>> > Wait, what? I thought the whole point of enforce is that it 
>> > will *not*
>> > be removed by the compiler, no matter what?
>>
>> No, the compiler is free to remove it if it can prove it will 
>> never be triggered.  eg if the condition is checking a ubyte < 
>> 1000.  If the assert in that example is never false, then the 
>> enforce is dead code.
>
> Actually, thinking about this some more...
>
> In this program the enforce can be removed
>
> assert(x < y);
> enforce(x < y);
>
> But not in this one:
>
> enforce(x < y);
> assert(x < y);
>
> because the compiler does need to take control flow into 
> account when applying the information in the assert.  In this 
> case the assert does not actually give the compiler any new 
> information.

Wait what? Now I'm confused.

x < y is guaranteed at point B (the assert).

x and y are unchanged between point A (the enforce) and point B.

Therefore, x < y is guaranteed at point A

No? Is there some sort of technical limitation?


More information about the Digitalmars-d mailing list