‹ BackHN Continuity

Thread

C++26: Trivial infinite loops are no longer undefined behaviour

173 points · 290 comments · ibobev

  1. JoshTriplett · · focus · HN ↗
    > When both conditions are met, the loop body is replaced with a call to std::this_thread::yield().

    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.

    1. saghm · · focus · HN ↗
      I guess given that it was UB before, the compiler was already allowed to put a system call here if it wanted for some reason
      1. fc417fc802 · · focus · HN ↗
        Yes, it was a horrible situation that has been replaced by an only slightly less horrible situation.
        1. saghm · · focus · HN ↗
          I don't totally agree with this. To me, UB is an order of magnitude worse than pretty much anything else, so this is more than "slightly less" horrible. I don't necessarily disagree that this is still horrible, but I also don't write an C++, so I'm mostly just commenting as an outside observer.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.