std::abort(3)
π std::abort π
okay so this is std::abort(3), the C++ Standard Libary page for the function that yeets your program into abnormal termination β but like, in a standardized way. bestie, it is literally the βnope, weβre done hereβ function. π«Ά
πΈ NAME πΈ
std::abort β yes bestie, itβs std::abort. no mystery, no plot twist, just the std::abort(3) manual page. itβs giving βabnormal program termination, but make it standardβ. π
β¨ Synopsis β¨
Defined in header <cstdlib>, and the signature changed in C++11, so keep up:
Defined in header <cstdlib>
void abort(); (until C++11)
[[noreturn]] void abort() noexcept; (since C++11)
Translation: before C++11 itβs plain void abort();; since C++11 itβs [[noreturn]] void abort() noexcept;.
okay so what does it actually do? std::abort causes abnormal program termination unless SIGABRT is being caught by a signal handler passed to std::signal and the handler does not return. no cap.
Destructors of variables with automatic, thread local (since C++11) and static storage durations are not called. Functions registered with std::atexit() and std::at_quick_exit (since C++11) are also not called. Whether open resources such as files are closed is implementation defined. An implementation defined status is returned to the host environment that indicates unsuccessful execution.
π Parameters π
(none) β bestie, there are literally no parameters. zero arguments, zero notes, zero chill. π
π₯ Return value π₯
None because it does not return. not a drill, not a vibe, it literally never comes back. π
π Exceptions π
Throws nothing. periodt.
π Notes π
- POSIX specifies that the
abort()function overrides blocking or ignoring theSIGABRTsignal. - Some compiler intrinsics, e.g.
__builtin_trap(gcc, clang, and icc) or__fastfail/__debugbreak(msvc), can be used to terminate the program as fast as possible.
π§ Example π§
okay this is the whole demo, bestie β run it and watch the destructors not show up:
// Run this code
#include <csignal>
#include <cstdlib>
#include <iostream>
class Tester
{
public:
Tester() { std::cout << "Tester ctor\n"; }
~Tester() { std::cout << "Tester dtor\n"; }
};
Tester static_tester; // Destructor not called
void signal_handler(int signal)
{
if (signal == SIGABRT)
std::cerr << "SIGABRT received\n";
else
std::cerr << "Unexpected signal " << signal << " received\n";
std::_Exit(EXIT_FAILURE);
}
int main()
{
Tester automatic_tester; // Destructor not called
// Setup handler
auto previous_handler = std::signal(SIGABRT, signal_handler);
if (previous_handler == SIG_ERR)
{
std::cerr << "Setup failed\n";
return EXIT_FAILURE;
}
std::abort(); // Raise SIGABRT
std::cout << "This code is unreachable\n";
}
Output:
Tester ctor
Tester ctor
SIGABRT received
notice: no Tester dtor lines, because destructors donβt run here. the vibe check failed on purpose π
β See also β
exitβ causes normal program termination with cleaning up (function)atexitβ registers a function to be called onstd::exit()invocation (function)quick_exitβ causes quick program termination without completely cleaning up (C++11) (function)at_quick_exitβ registers a function to be called onstd::quick_exitinvocation (C++11) (function)signalβ sets a signal handler for particular signal (function)terminateβ function called when exception handling fails (function)- C documentation for
abort
mwah π this pageβs source is http://cppreference.com, version/date 2024.06.10, and itβs the std::abort(3) manual page. byeee, go terminate something abnormally (responsibly) π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms