This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

### 3084. Termination in C++ is unclear

Section: 17.6 [support.start.term], 17.10.5 [exception.terminate] Status: New Submitter: JF Bastien Opened: 2018-03-15 Last modified: 2018-04-03

Priority: 3

View other active issues in [support.start.term].

View all other issues in [support.start.term].

View all issues with New status.

Discussion:

It's unclear how different termination facilities in C++ interact (and how they interact with the C termination facilities). Individually some of these functions try to handle corner cases, but hilarity ensues when combined with each other. As a simple example, can an `atexit` handler call `exit`? If not, can it call `quick_exit`, and can then `at_quick_exit` handler call `exit`? Is it possible to install an `atexit` handler from an `at_quick_exit`, without strongly happens before, while handling a separate `atexit` handler (and what happens then)?

The termination handlers and termination conditions I collected:

- returning from `main` calls `atexit` handlers.

- `atexit` / `exit`

- `at_quick_exit` / `quick_exit`

- `set_terminate`

- violating `noexcept` and other things that call `std::terminate` (see `[except.terminate]`)

- violating exception specification

- parallel algorithms leaving with uncaught exception

- some `std::signal` such as `SIGTERM`, `SIGSEGV`, `SIGINT`, `SIGILL`, `SIGABRT`, and (maybe?) `SIGFPE`.

- `set_unexpected` (now a zombie)

- `unexpected_handler` (now a zombie)

What's unclear is:

- Is termination handling a DAG?

- Which thread(s) are termination handlers called on?

- Is program termination Turing complete?

I've written a sample program which exercises some of this, see here.

[2018-04-02, Jens comments]

Any potential wording should carefully take [basic.start] into account, and maybe should actually be integrated into the core wording, not the library wording.

[2018-04-02 Priority set to 3 after discussion on the reflector.]

Proposed resolution: