▲ | bluGill 15 hours ago | |||||||||||||
In some languages overflow is asserted as a can't happen and so the optimizer will remove your checks | ||||||||||||||
▲ | appellations 13 hours ago | parent | next [-] | |||||||||||||
Best I can tell is that overflow is undefined behavior for signed ints in C/C++ so -O3 with gcc might remove a check that could only be true if UB occurred. The compound predicate in my example above coupled with the fact that the compiler doesn’t reason about the precondition in the prior assert (y is non-negative) means this specific example wouldn’t be optimized away, but bluGill does have a point. An example of an assert that might be optimized away:
| ||||||||||||||
| ||||||||||||||
▲ | appellations 13 hours ago | parent | prev [-] | |||||||||||||
Care to share a language where the compiler infers the semantic meaning of asserts and optimizes them away? I’ve never heard of this optimization. | ||||||||||||||
|