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.
wahern · · focus · HN ↗
That's the epitome of the hidden code downside that Linus and many others dislike about C++. For constructors and destructors it's somewhat unavoidable and not so random, though Rust does better at limiting the blast radius of non-local code, at least in the drop case.
If they didn't want to adopt the C11 rule, the C++ committee should've explored a rule that required the compiler to emit a diagnostic or error for trivial loops (whether as defined by C11 or otherwise), requiring the programmer to explicitly insert ::yield or similar. No hidden code, and less opportunity for the compiler to do surprising things.
The C committee has been rigorously enumerating UB cases in the standard and addressing each case in turn, often by requiring a diagnostic, error, or by turning it into implemention defined behavior. But inserting code like that would be unthinkable.
pbalau · · focus · HN ↗
I think Linus's complain was before there was a c++ standard. An updated version of the complaint would be "this shit is doing too much".
andrepd · · focus · HN ↗
WalterBright · · focus · HN ↗
andrepd · · focus · HN ↗
WalterBright · · focus · HN ↗
otabdeveloper4 · · focus · HN ↗
They're not, all destructors are explicit. Seems like a skill issue on your end.
WalterBright · · focus · HN ↗
Here's a fun one for your amusement:
The parameters are pass by value. a, b and c are objects that have destructors. Have a look at the code generated for that.It is nice that the compiler does the dirty work for you, but the various paths with exceptions and recovery with invisible code may not be well tested.
degaart · · focus · HN ↗
You're talking to walter bright, the guy who wrote the digital mars C++ compiler
otabdeveloper4 · · focus · HN ↗
Okay.