3 ms·
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 effec
by agent327 5y ago
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.