Mark qt_assert and qFatal as non-returning functions (excpt. MSVC)

This allows the compiler to optimise the code a bit better: since they
don't return, it can assume in the code after the Q_ASSERT that the
condition was true.

MSVC is the exception: with MSVC, we have the CrtDbgReport dialog,
which allows the developer to continue execution, inside the
debugger. Therefore, we can't mark any of those functions as
non-returning because they can, after all, return.

Unfortunately, the Q_ASSERT usually expands to no code in release
mode, so the improvement in code generation happens in debug mode
only...

Change-Id: I4d542d6853cd51c71ffab1d563ed64ef7c419115
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2012-03-23 19:05:17 -03:00 committed by Qt by Nokia
parent 886aea1250
commit 5d0da01b54
3 changed files with 14 additions and 0 deletions

View File

@ -896,6 +896,10 @@ inline void qUnused(T &x) { (void)x; }
class QString; class QString;
Q_CORE_EXPORT QString qt_error_string(int errorCode = -1); 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);
#if !defined(Q_ASSERT) #if !defined(Q_ASSERT)
@ -910,6 +914,9 @@ Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line);
#define QT_NO_PAINT_DEBUG #define QT_NO_PAINT_DEBUG
#endif #endif
#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);
#if !defined(Q_ASSERT_X) #if !defined(Q_ASSERT_X)

View File

@ -201,6 +201,9 @@ void QMessageLogger::fatal(const char *msg, ...)
va_list ap; va_list ap;
va_start(ap, msg); // use variable arg list va_start(ap, msg); // use variable arg list
qt_message(QtFatalMsg, context, msg, ap); qt_message(QtFatalMsg, context, msg, ap);
#ifndef Q_CC_MSVC
Q_UNREACHABLE();
#endif
va_end(ap); va_end(ap);
} }

View File

@ -113,6 +113,10 @@ public:
__attribute__ ((format (printf, 2, 3))) __attribute__ ((format (printf, 2, 3)))
#endif #endif
; ;
#ifndef Q_CC_MSVC
Q_NORETURN
#endif
void fatal(const char *msg, ...) void fatal(const char *msg, ...)
#if defined(Q_CC_GNU) && !defined(__INSURE__) #if defined(Q_CC_GNU) && !defined(__INSURE__)
__attribute__ ((format (printf, 2, 3))) __attribute__ ((format (printf, 2, 3)))