C++26 standard makes empty infinite loops well-defined behavior
The upcoming C++26 standard, via proposal P2809R3, changes the language so that trivial infinite loops like 'while(true);' are no longer undefined behavior. Previously, compilers such as Clang could legally assume such loops terminate and optimize them away entirely, sometimes causing code after the loop to execute unexpectedly. Because the fix was also accepted as a defect report, compiler vendors may backport it to earlier C++ standard modes too.
GoKawiil's interpretation of the reporting above, not reported fact.
This closes a long-standing and counterintuitive gap in C++'s undefined-behavior rules that could cause programs to behave in ways completely unrelated to their written logic, undermining trust in low-level code correctness. It reflects a broader multi-release effort in C++26 to shrink the scope of undefined behavior, following similar fixes for uninitialized reads and incomplete-type deletion. Developers writing embedded, systems, or synchronization code that intentionally spins forever will benefit from more predictable compiler behavior.
- C++26's P2809R3 makes trivial infinite loops without side effects well-defined rather than undefined behavior.
- Previously, compilers like Clang could delete such loops, causing unrelated code to run instead.
- The change is also a retroactive defect report, so it may apply even in older C++ standard modes on updated compilers.
Source: sandordargo.com, 2026-09-17
Published there as: “C++26: Trivial infinite loops are no longer undefined behaviour”
Read the original report → The summary and analysis above are GoKawiil's own, written from reporting by the source above. Facts and quotes belong to the original publisher.