Skip to content

Commit

Permalink
Remove QT_TERMINATE_ON_EXCEPTION: no longer needed
Browse files Browse the repository at this point in the history
When Marc introduced them way back in 2012 in commit
c856e37 ("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>
  • Loading branch information
thiagomacieira committed Jun 1, 2024
1 parent 4c12ae7 commit 9b2ae56
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 39 deletions.
30 changes: 0 additions & 30 deletions src/corelib/global/qassert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 0 additions & 6 deletions src/corelib/global/qexceptionhandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/corelib/global/qlogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9b2ae56

Please sign in to comment.