diff --git a/src/corelib/global/qassert.h b/src/corelib/global/qassert.h index c3696d10a8..063cdf89c4 100644 --- a/src/corelib/global/qassert.h +++ b/src/corelib/global/qassert.h @@ -14,6 +14,8 @@ QT_BEGIN_NAMESPACE +#if defined(__cplusplus) + #ifndef Q_CC_MSVC Q_NORETURN #endif @@ -73,6 +75,29 @@ inline T *q_check_ptr(T *p) { Q_CHECK_PTR(p); return p; } Q_ASSUME_IMPL(valueOfExpression);\ }(Expr) +// Don't use these in C++ mode, use static_assert directly. +// These are here only to keep old code compiling. +# define Q_STATIC_ASSERT(Condition) static_assert(bool(Condition), #Condition) +# define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message) + +#elif defined(Q_COMPILER_STATIC_ASSERT) +// C11 mode - using the _S version in case doesn't do the right thing +# define Q_STATIC_ASSERT(Condition) _Static_assert(!!(Condition), #Condition) +# define Q_STATIC_ASSERT_X(Condition, Message) _Static_assert(!!(Condition), Message) +#else +// C89 & C99 version +# define Q_STATIC_ASSERT_PRIVATE_JOIN(A, B) Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) +# define Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) A ## B +# ifdef __COUNTER__ +# define Q_STATIC_ASSERT(Condition) \ + typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __COUNTER__) [(Condition) ? 1 : -1]; +# else +# define Q_STATIC_ASSERT(Condition) \ + typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) [(Condition) ? 1 : -1]; +# endif /* __COUNTER__ */ +# define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition) +#endif // __cplusplus + QT_END_NAMESPACE #endif // QASSERT_H diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 83f9e1fc0d..b475c9cc64 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -91,10 +91,14 @@ #define QT_STRINGIFY2(x) #x #define QT_STRINGIFY(x) QT_STRINGIFY2(x) +inline void qt_noop(void) {} + #include #include #include +#include + #if defined (__ELF__) # define Q_OF_ELF #endif @@ -107,29 +111,6 @@ */ #define Q_UNUSED(x) (void)x; -#if defined(__cplusplus) -// Don't use these in C++ mode, use static_assert directly. -// These are here only to keep old code compiling. -# define Q_STATIC_ASSERT(Condition) static_assert(bool(Condition), #Condition) -# define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message) -#elif defined(Q_COMPILER_STATIC_ASSERT) -// C11 mode - using the _S version in case doesn't do the right thing -# define Q_STATIC_ASSERT(Condition) _Static_assert(!!(Condition), #Condition) -# define Q_STATIC_ASSERT_X(Condition, Message) _Static_assert(!!(Condition), Message) -#else -// C89 & C99 version -# define Q_STATIC_ASSERT_PRIVATE_JOIN(A, B) Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) -# define Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) A ## B -# ifdef __COUNTER__ -# define Q_STATIC_ASSERT(Condition) \ - typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __COUNTER__) [(Condition) ? 1 : -1]; -# else -# define Q_STATIC_ASSERT(Condition) \ - typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) [(Condition) ? 1 : -1]; -# endif /* __COUNTER__ */ -# define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition) -#endif - #ifndef __ASSEMBLER__ QT_BEGIN_NAMESPACE @@ -534,8 +515,6 @@ private: #endif // Q_OS_DARWIN -inline void qt_noop(void) {} - /* These wrap try/catch so we can switch off exceptions later. Beware - do not use more than one QT_CATCH per QT_TRY, and do not use @@ -591,10 +570,6 @@ Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qSharedBuild() noexcept; # define QT_DEBUG #endif -QT_BEGIN_INCLUDE_NAMESPACE -#include -QT_END_INCLUDE_NAMESPACE - #if 0 #pragma qt_class(QFunctionPointer) #endif