So there is a significant difference in semantics between Rust and C/C++ here.
So there is a significant difference in semantics between Rust and C/C++ here.
The standard may allow the generation of insane code, but a decent-quality compiler does not do so. The standard ought to be fixed.
Letting the compiler assume that a "switch" without a default will never go there is a great optimization too. Why not put that in the standard?
Actually, this is worse. Letting the loop be UB is like letting a true "if" be UB. Just never mind the code actually written; surely it doesn't mean what it says.
that's actually the case already. A missing default is UB if the switch condition does not match any of the cases. And C compilers already optimize accordingly.
Which ones?
If this optimizations are so important, how come Rust was designed in such a way to make them impossible? Also, how does this fit, e.g., the benchmark game results which show that Rust is faster than C for all benchmarks considered there ?
C does not have this guarantee (at least not in all cases). Also rust is compiled with the llvm backend, so my understanding is that in practice rust assumes that loops terminate. See:
https://github.com/rust-lang/rust/issues/28728
There are llvm directives that can be added to prevent the optimization, but they are rejected by the rust maintainers exactly because they would cause performance regressions.
If your loop infinitely writes the number 70 to an atomic int, it's fine.