checkedint call removal

Chris Cain via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 05:25:30 PDT 2014


On Thursday, 31 July 2014 at 08:36:12 UTC, John Colvin wrote:
> 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

That's not true. If x and y didn't follow x < y, then point B 
would never execute (enforce would throw an exception and point B 
would never have executed. So it's entirely possible for x >= y 
before point A, but never after point A. The enforce shouldn't 
ever be removed (but the assert technically can be without 
changing the behavior of the code).

The same logic holds for the other way,

     assert(x < y);
     enforce(x < y);

The enforce is redundant and can be removed there.


More information about the Digitalmars-d mailing list