diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-08-03 10:38:00 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-09 03:26:17 +0200 |
commit | c856e37c5fddec64d8635f3dae57b9cbea1aada4 (patch) | |
tree | 08233d5e1c6ee74811a1ae9e644d8b317c80818b /src/corelib/global/qglobal.h | |
parent | 7ef395224ea42a9a8d3469194d960077d7ff21eb (diff) |
Logging: mark qt_assert()/qt_assert_x()/qFatal() as nothrow
These functions are not supposed to return, not even by exception.
qt_message() _can_ throw, but we're fine with the compiler calling
std::terminate() then, since the backtrace will still include the
assertion location.
This behaviour is ensured by a new macro, QT_TERMINATE_ON_EXCEPTION,
which expands to something like
try { expr; } catch(...) { std::terminate(); }
if the compiler doesn't support Q_DECL_NOEXCEPT (but maybe
Q_DECL_NOTHROW), and to something like just
expr;
otherwise (including in the QT_NO_EXCEPTION case).
The real macro preserves scopes in all cases, and aims
to work even if <exception> isn't included in the TU it's used in,
so is a little bit more complex than that.
Change-Id: Ie6a2b7776e6aa77e57bd9aea6e184e5fa1cec81c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qglobal.h')
-rw-r--r-- | src/corelib/global/qglobal.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 6362e1b74b..5e58f5a4b0 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -546,11 +546,18 @@ inline void qt_noop(void) {} # 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 (0) #else # define QT_TRY try # define QT_CATCH(A) catch (A) # define QT_THROW(A) throw A # define QT_RETHROW throw +Q_NORETURN Q_CORE_EXPORT void qTerminate() Q_DECL_NOTHROW; +# ifdef Q_COMPILER_NOEXCEPT +# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (0) +# else +# define QT_TERMINATE_ON_EXCEPTION(expr) do { try { expr; } catch (...) { qTerminate(); } } while (0) +# endif #endif Q_CORE_EXPORT const char *qVersion(); @@ -593,7 +600,7 @@ Q_CORE_EXPORT QString qt_error_string(int errorCode = -1); #ifndef Q_CC_MSVC Q_NORETURN #endif -Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line); +Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) Q_DECL_NOTHROW; #if !defined(Q_ASSERT) # if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) @@ -610,7 +617,7 @@ Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line); #ifndef Q_CC_MSVC Q_NORETURN #endif -Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line); +Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line) Q_DECL_NOTHROW; #if !defined(Q_ASSERT_X) # if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) |