This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-04-18


2361. Unclear description of longjmp undefined behavior

Section: 17.13.3  [csetjmp.syn]     Status: open     Submitter: Zhihao Yuan     Date: 2017-10-20

According to 17.13.3 [csetjmp.syn] paragraph 2,

A setjmp/longjmp call pair has undefined behavior if replacing the setjmp and longjmp by catch and throw would invoke any non-trivial destructors for any automatic objects.

The intent is clear, that transferring control from point A to point B via longjmp has undefined behavior if throwing an exception at point A and catching it at point B would invoke non-trivial destructors. The wording could be more precise.

See also the corresponding editorial issue for additional discussion.

Notes from the October, 2018 teleconference:

There are a number of unanswered questions in the current wording, including the impact on the current exception (whether it still exists) after a longjmp out of a handler, the impact on the initialization of locks if jumping from the initialization of a local static data member, etc. One thought was to restrict use of longjmp to “plain C functions”. Another was to say if the program would have different behavior via the use of exceptions the behavior is undefined. There was no consensus on how to proceed.

Additional note, January, 2022:

See also library issues 1265 and 3652.