Issue 202828
Summary [libc++] `std::exit` does not call `terminate` when `atexit` handler exits via an exception
Labels libc++
Assignees
Reporter hubert-reinterpretcast
    Since at least C++98, `std::exit` has been specified such that `std::terminate` is called when an `atexit`-registered function exits via an exception (C++98 subclause 18.3 [lib.support.start.term] paragraph 5, https://wg21.link/support.start.term#9.1). libc++ does not meet this requirement as it allows both the search for a handler and stack unwinding itself to continue past the body of `std::exit`.

https://godbolt.org/z/18cPzKnTo

### Source (`<stdin>`)
```cpp
#include <stdlib.h>

void cleanup() { throw 42; }
void f [[gnu::weak]]() { exit(EXIT_FAILURE); }

volatile auto fn = cleanup;

int main(void) {
  atexit(fn);
  try {
    f();
  } catch (...) { return 0; }
}
```

### Compiler invocation
```
clang++ -std=c++26 --stdlib=libc++ -xc++ - -o prog
```

### Program invocation
```
./prog
```

### Actual program output
(rc=0)

### Expected program output
```
libc++abi: terminating due to uncaught exception of type int
```

### Compiler version info (clang++ -v)
```
clang version 23.0.0git (https://github.com/llvm/llvm-project.git e34dc2960ce94be069ac2a973c943b61ef9b3b23)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to