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 <giuseppe.dangelo@kdab.com>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
Thiago Macieira 2024-05-24 14:44:14 -03:00
parent 4c12ae7e67
commit 9b2ae564a5
3 changed files with 3 additions and 39 deletions

View File

@ -194,36 +194,6 @@ void qBadAlloc()
\sa Q_ASSERT(), Q_UNREACHABLE(), Q_LIKELY()
*/
/*!
\macro QT_TERMINATE_ON_EXCEPTION(expr)
\relates <QtGlobal>
\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 <QtAssert>

View File

@ -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

View File

@ -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