News for hackers. Stuff that matters.
Re:“Pack it in, mathematicians, someone owes LLVM a million ... by agent327 on Thursday August 19, 2021 @10:50AM (#28234547)
There is no side effect. The loop only interacts with variable 'x', which is discarded after the function ends. Since it is not observed, there is no side effect.

That leaves only the loop itself, which can run infinitely long (which would be UB, and the compiler is free to assume that won't happen), or it won't, in which case it will always return true. Thus, like them or not, the rules of C++ allow this particular outcome.

I can't say I like this kind of optimisation. Sure, you can construct neat circus tricks with it like this, but other than that it seems pretty pointless for real-world software, and something that could easily turn a simple mistake into a debugging disaster.

There are no comments on this comment yet.