Release
C++26: Trivial infinite loops are no longer undefined behaviour -- Sandor Dargo
isocpp.org · By Blog Staff ·
The Brief
- C++26 no longer treats trivial infinite loops such as while (true); as undefined behaviour, per P2809R3.
- Previously, compilers could optimize such loops away entirely.
- The article also covers the history of C++'s forward-progress rules.
Why it matters
Once C++26 is in effect, a trivial infinite loop is no longer undefined behaviour, so compilers should not optimize it away, which affects code that relies on such loops.
Who’s affected
- C++ developers
- C++26
- #c++
- #c++26
- #undefined-behavior
- #compilers
- #standards
C++26 fixes a surprising source of undefined behaviour: trivial infinite loops such as while (true); , which compilers previously could optimize away entirely. This article explores the history of C++’s forward-progress rules, the changes introduced by P2809R3, and why the fix…