summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2011-10-14 12:58:54 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-19 19:25:37 +0200
commit663cd1771883e1e7ac9c1a0dc8b797601b59ba17 (patch)
treecd25c63a24ed4a59c077bd0ee7d4fda8d878bc6c /src/corelib/global
parent0b6d4a2d65536670423778f53269026b12552017 (diff)
Introduce Q_STATIC_ASSERT
Example of message of failed assert (gcc 4.6, file tst_qglobal.cpp:300): tst_qglobal.cpp:300:92: error: invalid application of ‘sizeof’ to incomplete type ‘QStaticAssertFailure<false>’ Change-Id: Ic1798094f718eaad388d754034115aafbbb6bd5e Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qglobal.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 5f8e6be893..ee601859b7 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -1785,6 +1785,15 @@ Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *
# endif
#endif
+// Intentionally undefined
+template <bool Test> class QStaticAssertFailure;
+template <> class QStaticAssertFailure<true> {};
+
+#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
+#define Q_STATIC_ASSERT(...) \
+ enum {Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) = sizeof(QStaticAssertFailure<bool(__VA_ARGS__)>)}
+
Q_CORE_EXPORT void qt_check_pointer(const char *, int);
Q_CORE_EXPORT void qBadAlloc();