Movement against float.init being nan

Adam D Ruppe destructionator at gmail.com
Tue Aug 30 12:17:36 UTC 2022


On Tuesday, 30 August 2022 at 12:07:52 UTC, wjoe wrote:
> Is this true for asserts w/o side effects?

Yes. -release should seriously *never* be used for a lot of 
reasons, but read this part of the spec:

https://dlang.org/spec/expression.html#assert_expressions

> 1. The first AssignExpression must evaluate to true. If it does 
> not, an Assert Failure has occurred and the program enters an 
> Invalid State.

Notice that it doesn't say "must evaluate to true if actually 
evaluated", it just says must evaluate to true. If it would have 
failed, even if not actually compiled in, the program has *still* 
entered the Invalid State.

> 8. Undefined Behavior: Once in an Invalid State the behavior of 
> the continuing execution of the program is undefined.

> Implementation Defined: Whether the first AssertExpression is 
> evaluated or not at runtime is typically set with a compiler 
> switch.

This combines to mean an optimizer is free to assume the asserts 
were all true as it moves forward which can get pretty random if 
it was never actually tested.


I'm not sure if this is what Timon had in mind but it is its own 
thing to watch out for.


More information about the Digitalmars-d mailing list