summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2013-09-22 05:17:22 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-22 10:32:42 +0200
commitab55f9f39b8c7716500d74dd32ae813df76623c4 (patch)
treeb5ade8fbc984e7e205841c3d22f9fb924704bc80 /src/corelib/global
parent1b34df6ea600bd361768be4091a255987e38f91c (diff)
Q_STATIC_ASSERT: use __COUNTER__ instead of __LINE__ if the compiler supports it
When using __LINE__ to construct unique names, use of Q_STATIC_ASSERT is limited to one instance per line of code. On compilers that support __COUNTER__ (GCC and MSVC, probably others), we can get around that limitation by using that one to always get a new unique number, so use it. Change-Id: I89bcfaa32376b7a665f03e4275e89b13fa3e650d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qglobal.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index b4830bda1f..b1a22ddf03 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -656,8 +656,13 @@ 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
+#ifdef __COUNTER__
+#define Q_STATIC_ASSERT(Condition) \
+ enum {Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __COUNTER__) = sizeof(QStaticAssertFailure<!!(Condition)>)}
+#else
#define Q_STATIC_ASSERT(Condition) \
enum {Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) = sizeof(QStaticAssertFailure<!!(Condition)>)}
+#endif /* __COUNTER__ */
#define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition)
#endif