checkedint call removal
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jul 28 05:52:05 PDT 2014
On Monday, 28 July 2014 at 12:08:39 UTC, Daniel Murphy wrote:
> "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.
Ok. What about this:
int c;
void foo(int a)
{
if(a < 0) c++;
assert(a > 0);
}
I presume that cannot be optimised away entirely to:
void foo(int a) {}
?
More information about the Digitalmars-d
mailing list