summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-08-08 11:23:54 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2022-08-11 09:43:30 +0200
commitc77c5b391e36bac9f810c1557688aca5936c6807 (patch)
treef00d88fa9092e74a60caca25650a5742797249f3 /src/corelib
parent43b59a842a86140fa5f5da2f0d66d0d916883c8f (diff)
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>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qassert.h25
-rw-r--r--src/corelib/global/qglobal.h33
2 files changed, 29 insertions, 29 deletions
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 <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
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 <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