From a861463c3c7a216632ae81a90e085fb99579d544 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 26 Mar 2012 10:31:58 -0300 Subject: [PATCH] Add a Q_NORETURN macro to mark a function that never returns This is implemented for GCC, ICC, Clang and MSVC. With this macro, the compiler can generate better code because it knows that the function being called will not return. Change-Id: Iea2bc7be464606639be65ccb73911d7ed1b29a64 Reviewed-by: Oswald Buddenhagen --- src/corelib/global/qcompilerdetection.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index c9f59454b2..a043e5e072 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -90,6 +90,7 @@ # define Q_DECL_ALIGN(n) __declspec(align(n)) # define Q_ASSUME(expr) __assume(expr) # define Q_UNREACHABLE() __assume(0) +# define Q_NORETURN __declspec(noreturn) /* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */ # if defined(__INTEL_COMPILER) # define Q_CC_INTEL @@ -161,6 +162,7 @@ # define Q_DECL_ALIGN(n) __attribute__((__aligned__(n))) # define Q_LIKELY(expr) __builtin_expect(!!(expr), true) # define Q_UNLIKELY(expr) __builtin_expect(!!(expr), false) +# define Q_NORETURN __attribute__((__noreturn__)) # if !defined(QT_MOC_CPP) # define Q_PACKED __attribute__ ((__packed__)) # define Q_NO_PACKED_REFERENCE @@ -395,6 +397,10 @@ # error "Qt has not been tested with this compiler - see http://www.qt-project.org/" #endif +#ifndef Q_NORETURN +# define Q_NORETURN +#endif + /* * C++11 support *