Is an infinite loop without side effects UB?

Famously, an infinite loop without side effects is UB in C++. I can write similar code in Safe Rust. Is such code well-defined? What is its defined behavior?

1 Like

It's well-defined behavior precisely because it can be written in safe Rust and safe Rust is not supposed to allow UB.

There were few bugs in compiler in the past, though.


It runs forever with no side-effects.

Indeed, probably discussed here:


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.