From 9b2ae564a59656d9cf49b141e70f5958b4fb79a4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 24 May 2024 14:44:14 -0300 Subject: [PATCH] Remove QT_TERMINATE_ON_EXCEPTION: no longer needed When Marc introduced them way back in 2012 in commit c856e37c5fddec64d8635f3dae57b9cbea1aada4 ("Logging: mark qt_assert()/ qt_assert_x()/qFatal() as nothrow"), he said: > QT_TERMINATE_ON_EXCEPTION, which expands to something like > try { expr; } catch(...) { std::terminate(); } > if the compiler doesn't support Q_DECL_NOEXCEPT Well, all compilers now support noexcept, so we always had the plain do { } while (0) expansion instead. Change-Id: If3345151ddf84c43a4f1fffd17d27dbc0f100ec7 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Ahmad Samir --- src/corelib/global/qassert.cpp | 30 ------------------------- src/corelib/global/qexceptionhandling.h | 6 ----- src/corelib/global/qlogging.cpp | 6 ++--- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/src/corelib/global/qassert.cpp b/src/corelib/global/qassert.cpp index 6a29cbfa21c..7c0064ac2ff 100644 --- a/src/corelib/global/qassert.cpp +++ b/src/corelib/global/qassert.cpp @@ -194,36 +194,6 @@ void qBadAlloc() \sa Q_ASSERT(), Q_UNREACHABLE(), Q_LIKELY() */ -/*! - \macro QT_TERMINATE_ON_EXCEPTION(expr) - \relates - \internal - - In general, use of the Q_DECL_NOEXCEPT macro is preferred over - Q_DECL_NOTHROW, because it exhibits well-defined behavior and - supports the more powerful Q_DECL_NOEXCEPT_EXPR variant. However, - use of Q_DECL_NOTHROW has the advantage that Windows builds - benefit on a wide range or compiler versions that do not yet - support the C++11 noexcept feature. - - It may therefore be beneficial to use Q_DECL_NOTHROW and emulate - the C++11 behavior manually with an embedded try/catch. - - Qt provides the QT_TERMINATE_ON_EXCEPTION(expr) macro for this - purpose. It either expands to \c expr (if Qt is compiled without - exception support or the compiler supports C++11 noexcept - semantics) or to - \snippet code/src_corelib_global_qglobal.cpp qterminate - otherwise. - - Since this macro expands to just \c expr if the compiler supports - C++11 noexcept, expecting the compiler to take over responsibility - of calling std::terminate() in that case, it should not be used - outside Q_DECL_NOTHROW functions. - - \sa Q_DECL_NOEXCEPT, Q_DECL_NOTHROW, qTerminate() -*/ - /*! \macro void Q_UNREACHABLE() \relates diff --git a/src/corelib/global/qexceptionhandling.h b/src/corelib/global/qexceptionhandling.h index 76c6185c3ea..7ffd0798f6f 100644 --- a/src/corelib/global/qexceptionhandling.h +++ b/src/corelib/global/qexceptionhandling.h @@ -28,17 +28,11 @@ Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() noexcept; # define QT_CATCH(A) else # define QT_THROW(A) qt_noop() # define QT_RETHROW qt_noop() -# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false) #else # define QT_TRY try # define QT_CATCH(A) catch (A) # define QT_THROW(A) throw A # define QT_RETHROW throw -# ifdef Q_COMPILER_NOEXCEPT -# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false) -# else -# define QT_TERMINATE_ON_EXCEPTION(expr) do { try { expr; } catch (...) { qTerminate(); } } while (false) -# endif #endif QT_END_NAMESPACE diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 82b139e4d61..efeec370943 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -834,7 +834,7 @@ void QMessageLogger::fatal(const QLoggingCategory &cat, const char *msg, ...) co va_list ap; va_start(ap, msg); // use variable arg list - QT_TERMINATE_ON_EXCEPTION(qt_message(QtFatalMsg, ctxt, msg, ap)); + qt_message(QtFatalMsg, ctxt, msg, ap); va_end(ap); #ifndef Q_CC_MSVC_ONLY @@ -858,7 +858,7 @@ void QMessageLogger::fatal(QMessageLogger::CategoryFunction catFunc, va_list ap; va_start(ap, msg); // use variable arg list - QT_TERMINATE_ON_EXCEPTION(qt_message(QtFatalMsg, ctxt, msg, ap)); + qt_message(QtFatalMsg, ctxt, msg, ap); va_end(ap); #ifndef Q_CC_MSVC_ONLY @@ -877,7 +877,7 @@ void QMessageLogger::fatal(const char *msg, ...) const noexcept QInternalMessageLogContext ctxt(context); va_list ap; va_start(ap, msg); // use variable arg list - QT_TERMINATE_ON_EXCEPTION(qt_message(QtFatalMsg, ctxt, msg, ap)); + qt_message(QtFatalMsg, ctxt, msg, ap); va_end(ap); #ifndef Q_CC_MSVC_ONLY