‹ BackHN Continuity

Thread

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

173 points · 290 comments · ibobev

  1. BobbyTables2 · · focus · HN ↗
    TLDR: For almost 1/6 of a century, the C++ standards broke the simplest infinite loop and only just recently fixed it.

    Idiots!

    Don’t they really that people write real programs to solve real problems? This isn’t a theoretical academic exercise!

    1. bryanlarsen · · focus · HN ↗
      They also realized that people choose compilers based on performance benchmarks, and that insane optimizations let them win.
      1. vlovich123 · · focus · HN ↗
        Until Rust proved actually you can get really good or better performance if the language itself is better. I really don’t know how C++ digs itself out of the UB hole it has dug.
        1. bryanlarsen · · focus · HN ↗
          Probably by working together with Rust. Eliminating undefined behavior from unsafe Rust is a big deal for the Rust community at the moment. And given that most unsafe rust code exists to call into C or C++, concepts like pointer provenance need to be extended. And proper pointer provenance guarantees can both decrease UB and increase optimization potential.

          IIUC, my understanding is shallow.

          1. vlovich123 · · focus · HN ↗
            That's a niche level thing that helps in some scenarios, and generally not as much for C++ which is much more weakly typed than Rust is. Weak typing + static typing is why safety problems in C++ are going to be really difficult to fix without fundamentally changing the language.
            1. bryanlarsen · · focus · HN ↗
              I expect some changes to the language from this direction, some way to attach provenance information or limitations to a pointer. Presumably through a #pragma at first. Strict typing in the C++ sense, not the Rust sense. An annotation like "volatile".

              Pointer provenance is just one example, there are others.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.