C++26: Trivial infinite loops are no longer undefined behaviour
Thread
Unofficial Hacker News client; not affiliated with Y Combinator.
C++26: Trivial infinite loops are no longer undefined behaviour
Unofficial Hacker News client; not affiliated with Y Combinator.
JoshTriplett · · focus · HN ↗
Insert screaming here.
An infinite loop, with no library calls whatsoever, gets a system call inserted. That's a horrible surprise waiting to happen.
The entire concept of the "forward progress guarantee" is broken. An infinite loop should compile to an infinite loop. Nothing more, nothing less.
saghm · · focus · HN ↗
fc417fc802 · · focus · HN ↗
saghm · · focus · HN ↗
chowells · · focus · HN ↗
Do I fully believe all of the above? Not exactly. But compiler authors do. Does it make a really good argument to never use C or C++? Yes. If only we had 50 years of optimization work in any language with better semantics.
saghm · · focus · HN ↗
JoshTriplett · · focus · HN ↗
throwaway786678 · · focus · HN ↗
That UB was added in C++11.
chowells · · focus · HN ↗
TuxSH · · focus · HN ↗
In any case stuff like __asm__ __volatile__("" ::: "memory") prevent such optimizations in the rare case you do need branch-to-self.
classified · · focus · HN ↗
The insidious thing about UB is that it doesn't necessarily have to be executed to wreck your program. UB is not primarily about runtime behavior, it's about how the compiler interprets your code. The behavior that is undefined is your compiler's behavior.
chowells · · focus · HN ↗
cryptonector · · focus · HN ↗
saghm · · focus · HN ↗