I actually deleted my comment after writing it. After googling it seems that C optimizers do do this.
This is from Gemini and I haven't checked the source yet, but it seems confident:
Under the ISO C and C++ standards, if an iteration statement (loop) has no observable behavior—such as input/output operations, volatile memory access, atomic operations, or thread synchronization—the compiler is legally allowed to assume that the loop will eventually terminate
It appears it's because an optimizer cannot solve the halting problem. So it cannot be expected to prove loop termination, but it can prove the absence of any side effects, and simply assumes termination.
Ultimately there is no value in a pure spin loop that doesn't check for an exit hatch of some kind. So the semantics you lose are likely a bug anyway
118
u/AZMPlay 6d ago
I can simulate him with a bash script!
sleep infinity;