Skip to content- Sources: primary, discussion
- Summary: A
while (true); loop with no side effects was undefined behaviour before C++26 under the C++11 forward progress rules, so the optimizer could delete it, and the post shows Clang doing exactly that and falling through into a linker-adjacent function. P2809R3 defines a narrow category, a trivially empty body plus a controlling constant expression that is true, whose body becomes a call to std::this_thread::yield, and amends the forward progress guarantee to allow continuing such a loop, while on freestanding implementations whether the yield replacement happens at all is implementation-defined. The proposal was also accepted as a defect report, so implementations may apply it to earlier language modes, which is why the old behaviour may not reproduce even in C++20, and C has had the equivalent rule since C11. - Why it matters: The halt-on-error loop used in embedded and kernel code with no operating system to exit to could be deleted, leaving the device running on through corrupt state.