(no title)
appellations | 4 months ago
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:
int addFive(int x) {
int y = x + 5;
assert(y >= x);
return y;
}
uecker|4 months ago
comex|4 months ago
https://gcc.godbolt.org/z/3Y4aheG6x