I could have also phrased this as What constitutes observable behavior?
The C++ Standard talks a lot about observable behavior, but I am not really sure if program termination is part of observable behavior.
That is, given a program such as:
int main() {
for(;;) {}
return 0;
}
is a conforming implementation allowed to ever terminate this program?
Yes it is legal for the compile to generate an empty main body for the above code (thus terminating almost immediately).
The C++0x FCD says 6.5 says (pay special attention to the note):
So the compiler can assume that your
forloop will terminate and since the body is empty it can optimize it away altogether.The quotation from the draft was copied from this question and verified against my copy.