>>106286675 (OP)
>>106286730
>>106286736
>>106286759
While I am not an expert on this subject, this is my impression:
Having a trivial infinite loop that does nothing was in versions of C++ prior to C++26 undefined behavior, for the sake of letting the compiler make assumptions and optimize further.
In C++26, this is no longer undefined behavior.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2809r3.html
While this may constrain what optimizations can be done, if a programmer writes a trivial infinite loop, the intention was probably not that optimizations should be done.
A subset of other types of non-trivial infinite loops still cause undefined behavior as I understand it, to enable optimization.
These decisions are trade-offs. For instance, the Rust ecosystem is in some ways some of the time working in the other direction, providing more functions that are unsafe for the sake of enabling programmers to write programs that have better optimization possibilities, at the cost of increased difficulty and risk.
https://doc.rust-lang.org/std/primitive.i64.html#method.unchecked_add
Though Rust does hide it behind its "unsafe" keyword, making it clearly opt-in regarding risk of undefined behavior (though Rust's guarantees has some issues, drawbacks and practical limitations, such as when using no_std).
The past behavior of C++ caused a bug in Rust once.
https://github.com/rust-lang/rust/issues/28728
In general, except for some patterns of usage like typical trivial infinite loops, if a non-trivial infinite loop has no IO and such, it is likely a bug by the programmer, since such a loop would basically never be useful.