Is a program that never terminates a valid C++ program?

Yes. From [intro.progress]

The implementation may assume that any thread will eventually do one of the following:

  • terminate,
  • make a call to a library I/O function,
  • perform an access through a volatile glvalue, or
  • perform a synchronization operation or an atomic operation.

[ Note: This is intended to allow compiler transformations such as removal of empty loops, even when termination cannot be proven. — end note ]


There is nothing in the C++ standard that requires the program, or any given thread, to terminate. The closest thing to that is [intro.progress]p1, which says

The implementation may assume that any thread will eventually do one of the following:

  • terminate,
  • make a call to a library I/O function,
  • perform an access through a volatile glvalue, or
  • perform a synchronization operation or an atomic operation.

[ Note: This is intended to allow compiler transformations such as removal of empty loops, even when termination cannot be proven.  — end note ]

As long as there is some observable behavior, eventually, or as long as it spends all its time blocked on an I/O operation or another blocking library call, this doesn't apply, and the program is valid (assuming it meets all the other validity criteria).