Move Q_STATIC_ASSERT* macros to qassert.h
This requires moving the include statement for qassert.h in qglobal.h up, outside the #if defined(__cplusplus) check, to make the macros available when __cplusplus isn't defined. Also move qt_noop() up, before the include of qassert.h, this will later go to a separate header. Task-number: QTBUG-99313 Change-Id: I0f3f1ca77819a86623eebaf8adeba226c190fd37 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
43b59a842a
commit
c77c5b391e
|
|
@ -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 <assert.h> 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
|
||||
|
|
|
|||
|
|
@ -91,10 +91,14 @@
|
|||
#define QT_STRINGIFY2(x) #x
|
||||
#define QT_STRINGIFY(x) QT_STRINGIFY2(x)
|
||||
|
||||
inline void qt_noop(void) {}
|
||||
|
||||
#include <QtCore/qsystemdetection.h>
|
||||
#include <QtCore/qprocessordetection.h>
|
||||
#include <QtCore/qcompilerdetection.h>
|
||||
|
||||
#include <QtCore/qassert.h>
|
||||
|
||||
#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 <assert.h> 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 <QtCore/qassert.h>
|
||||
QT_END_INCLUDE_NAMESPACE
|
||||
|
||||
#if 0
|
||||
#pragma qt_class(QFunctionPointer)
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue