https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90682
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2019-05-30 Ever confirmed|0 |1 --- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #0) > I think we should treat a null handler as equivalent to abort, e.g. > > --- a/libstdc++-v3/libsupc++/eh_terminate.cc > +++ b/libstdc++-v3/libsupc++/eh_terminate.cc > @@ -44,7 +44,8 @@ __cxxabiv1::__terminate (std::terminate_handler handler) > throw () > { > __try > { > - handler (); > + if (handler) > + handler (); > std::abort (); > } > __catch(...) Another option would be to make set_terminate(nullptr) consistent with pmr::set_default_resource(nullptr), i.e. restore the default: --- a/libstdc++-v3/libsupc++/eh_terminate.cc +++ b/libstdc++-v3/libsupc++/eh_terminate.cc @@ -73,6 +73,14 @@ std::unexpected () std::terminate_handler std::set_terminate (std::terminate_handler func) throw() { +#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE && __cpp_exceptions + if (!func) + func = __gnu_cxx::__verbose_terminate_handler; +#else + if (!func) + func = std::abort; +#endif + std::terminate_handler old; #if ATOMIC_POINTER_LOCK_FREE > 1 __atomic_exchange (&__terminate_handler, &func, &old, __ATOMIC_ACQ_REL); This would mean that std::get_terminate() never returns a null pointer, and we don't need to check for null in std::terminate(). This is what libc++ does. Whatever we do for terminate/set_terminate we should also do for unexpected/set_unexpected, e.g. @@ -100,6 +108,9 @@ std::get_terminate () noexcept std::unexpected_handler std::set_unexpected (std::unexpected_handler func) throw() { + if (!func) + func = std::terminate; + std::unexpected_handler old; #if ATOMIC_POINTER_LOCK_FREE > 1 __atomic_exchange (&__unexpected_handler, &func, &old, __ATOMIC_ACQ_REL);