assert semantic change proposal

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 6 08:49:47 PDT 2014


On 08/06/14 17:02, Matthias Bentrup via Digitalmars-d wrote:
> But even if there is no explicit assert()/assume() given by the developer, I guess the optimizer is free to insert assumes that are provably correct, e.g.
> 
>   while(running) {
>     ...don't assign to running, don't break...
>   }
> 
> is equivalent to
> 
>   while(running) {
>     ...don't assign to running, don't break...
>   }
>   assume(!running);

In the "running==true" case that 'assume' will never be reached...

> is equivalent to
> 
>   assume(!running);
>   while(running) {
>     ...don't assign to running, don't break...
>   }

... so, no, this transformation is not a valid one.

> So I take the compiler is allowed to throw away code without any asserts already ?

It can do whatever it wants, as long as the observable behavior does
not change. `Assume` removes that restriction as soon as a failing
assert is reached. 

artur


More information about the Digitalmars-d mailing list