The C ++ specification can only define things that are contained in the C ++ specification. Remember: the C ++ specification defines the behavior of the virtual machine that it defines. And if he does not determine that something can happen, he, of course, does not determine the behavior of C ++ around what might happen that he does not say.
According to the C ++ specification, a stream can exit in exactly three ways: returning from its main function, throwing an exception through its main function, and calling a direct process (like using std::terminate
or similar functions). In short, a C ++ stream cannot exit in any other way. There is no ExitThread
function in standard C ++. Similarly, std::thread
cannot kill a thread, either externally or internally.
Therefore, everything that causes this thing that C ++ talks about cannot be, by definition, undefined. I think this would not even be “undefined behavior”; it would be in that foggy space in which there would be a thread before C ++ 11 really established how the threads interact.
The same goes for “signals,” no matter what it is. The C ++ specification does not say that this can lead to a function exit. There will be dragons.
As for longjmp
, that is covered by the behavior of longjmp
. When you use longjmp
to exit a function, this function never ends, as if you were using throw
and catch
. And in C ++, an object is built only after the completion of its constructor. Therefore, the initialization of the object was never completed, and it was not initialized.
I don't have the ISO C specification (which references C ++ for longjmp
behavior), but C ++ 11 strongly suggests you equate throw
/ catch
with longjmp
/ setjmp
if you get undefined behavior:
§18.10 [support.runtime] p4:
The functional signature longjmp (jmp_buf jbuf, int val) has more limited behavior in this International Standard. The pair of setjmp / longjmp codes has undefined behavior if replacing setjmp and longjmp with catch and throw will cause any non-trivial destructors for any automatic objects.
Therefore, I do not think this is unproven. It may not be pretty and neat, but all the parts are there.