From: Matthias Maier Date: Fri, 15 Jun 2018 19:54:05 +0000 (-0500) Subject: Exceptions: Do not set verbose terminate handler X-Git-Tag: v9.1.0-rc1~1024^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F6776%2Fhead;p=dealii.git Exceptions: Do not set verbose terminate handler All of this is entirely redundant nowadays. libstdc++ defaults to setting the verbose terminate handler since (almost) forever. So all we end up doing is setting something that is already the default. Remove it. Rationale: - libstdc++ (gcc) switched to __gnu_cxx::__verbose_terminate_handler a long time ago [1]. - libc++ (clang) has its own verbose terminate handler. And above code snippet never worked there [2]: Example: ``` struct my_exception : public std::runtime_error { my_exception() : std::runtime_error("Nope, not with me") {} }; int main() { throw my_exception(); } ``` libstdc++: terminate called after throwing an instance of 'my_exception' what(): Nope, not with me zsh: abort (core dumped) ./a.out libc++: terminating with uncaught exception of type my_exception: Nope, not with me [1] https://gcc.gnu.org/onlinedocs/libstdc++/manual/termination.html [2] The DEAL_II_HAVE_VERBOSE_TERMINATE check fails for libc++ because (of course) no __gnu_cxx:: namespace is available... --- diff --git a/cmake/checks/check_02_compiler_features.cmake b/cmake/checks/check_02_compiler_features.cmake index 9046f50d22..a2b90d1c4c 100644 --- a/cmake/checks/check_02_compiler_features.cmake +++ b/cmake/checks/check_02_compiler_features.cmake @@ -25,7 +25,6 @@ # DEAL_II_COMPILER_USE_VECTOR_ARITHMETICS # DEAL_II_VECTOR_ITERATOR_IS_POINTER # DEAL_II_HAVE_BUILTIN_EXPECT -# DEAL_II_HAVE_VERBOSE_TERMINATE # DEAL_II_HAVE_GLIBC_STACKTRACE # DEAL_II_HAVE_LIBSTDCXX_DEMANGLER # DEAL_II_COMPILER_HAS_ATTRIBUTE_PRETTY_FUNCTION @@ -125,41 +124,6 @@ CHECK_CXX_SOURCE_COMPILES( DEAL_II_HAVE_BUILTIN_EXPECT) -# -# Newer versions of GCC have a very nice feature: you can set -# a verbose terminate handler, that not only aborts a program -# when an exception is thrown and not caught somewhere, but -# before aborting it prints that an exception has been thrown, -# and possibly what the std::exception::what() function has to -# say. Since many people run into the trap of not having a -# catch clause in main(), they wonder where that abort may be -# coming from. The terminate handler then at least says what is -# missing in their program. -# -# This test checks whether this feature is available. -# -# - Matthias Maier, rewritten 2012 -# -CHECK_CXX_SOURCE_COMPILES( - " - #include - namespace __gnu_cxx - { - extern void __verbose_terminate_handler (); - } - struct preload_terminate_dummy - { - preload_terminate_dummy() - { - std::set_terminate (__gnu_cxx::__verbose_terminate_handler); - } - }; - static preload_terminate_dummy dummy; - int main() { throw 1; return 0; } - " - DEAL_II_HAVE_VERBOSE_TERMINATE) - - # # Check whether glibc-like stacktrace information is available # for the Exception class. If it is, then try to also determine diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index d66211ef98..9b4a45be3e 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -88,7 +88,6 @@ #cmakedefine DEAL_II_COMPILER_USE_VECTOR_ARITHMETICS #cmakedefine DEAL_II_VECTOR_ITERATOR_IS_POINTER #cmakedefine DEAL_II_HAVE_BUILTIN_EXPECT -#cmakedefine DEAL_II_HAVE_VERBOSE_TERMINATE #cmakedefine DEAL_II_HAVE_GLIBC_STACKTRACE #cmakedefine DEAL_II_HAVE_LIBSTDCXX_DEMANGLER #cmakedefine __PRETTY_FUNCTION__ @__PRETTY_FUNCTION__@ diff --git a/source/base/exceptions.cc b/source/base/exceptions.cc index 5f869b9153..c9f83a897a 100644 --- a/source/base/exceptions.cc +++ b/source/base/exceptions.cc @@ -572,34 +572,3 @@ namespace deal_II_exceptions DEAL_II_NAMESPACE_CLOSE - - - -// Newer versions of gcc have a very nice feature: you can set a verbose -// terminate handler, that not only aborts a program when an exception is -// thrown and not caught somewhere, but before aborting it prints that an -// exception has been thrown, and possibly what the std::exception::what() -// function has to say. Since many people run into the trap of not having a -// catch clause in main(), they wonder where that abort may be coming from. -// The terminate handler then at least says what is missing in their -// program. -#ifdef DEAL_II_HAVE_VERBOSE_TERMINATE -namespace __gnu_cxx -{ - extern void - __verbose_terminate_handler(); -} - -namespace -{ - struct preload_terminate_dummy - { - preload_terminate_dummy() - { - std::set_terminate(__gnu_cxx::__verbose_terminate_handler); - } - }; - - static preload_terminate_dummy dummy; -} // namespace -#endif