On Wed, Mar 14, 2018 at 6:50 PM, Aaron Ballman <aaron@aaronballman.com> wrote:
Infinite loops are undefined behavior because you'd have to solve the
halting problem in order to determine whether any given code path is
dynamically reachable. So presence of an infinite loop is UB in order
to allow optimizers to generate code assuming the behavior never
occurs.

As soon as you mention the word "optimizer" you are lost.

Compilers don't need to solve anything.  All they need to do is to model the
abstract machine on the underlying computer.  If the abstract machine executes
an infinite loop, so does the computer.  As the programmer wrote it.