summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qalgorithms.h
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2013-04-18 07:19:03 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-18 22:27:04 +0200
commitc5a3cfa488ec5653cb026060e2b8f8b6a702d020 (patch)
treebd40135eb88df60948ddd4e7207c16463601a11f /src/corelib/tools/qalgorithms.h
parent94758589fe49a0d7b79922e78246a0cb6335278b (diff)
Compile with Clang.
This bug surfaced after we switched Mac over to use clang's libstdc++, which has __builtin_popcount but does not mark it as constexpr. Change-Id: I4260af48b00c6db3322e52fb113075d305b1e1ec Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
Diffstat (limited to 'src/corelib/tools/qalgorithms.h')
-rw-r--r--src/corelib/tools/qalgorithms.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h
index fecb9120eb..8337afcb9d 100644
--- a/src/corelib/tools/qalgorithms.h
+++ b/src/corelib/tools/qalgorithms.h
@@ -516,9 +516,17 @@ Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFindHelper(RandomAccessIterator
} //namespace QAlgorithmsPrivate
+
+// Use __builtin_popcount on gcc. Clang claims to be gcc
+// but has a bug where __builtin_popcount is not marked as
+// constexpr.
+#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG)
+#define QALGORITHMS_USE_BUILTIN_POPCOUNT
+#endif
+
Q_DECL_CONSTEXPR inline uint qPopulationCount(quint32 v)
{
-#ifdef Q_CC_GNU
+#ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT
return __builtin_popcount(v);
#else
// See http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
@@ -531,7 +539,7 @@ Q_DECL_CONSTEXPR inline uint qPopulationCount(quint32 v)
Q_DECL_CONSTEXPR inline uint qPopulationCount(quint8 v)
{
-#ifdef Q_CC_GNU
+#ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT
return __builtin_popcount(v);
#else
return
@@ -541,7 +549,7 @@ Q_DECL_CONSTEXPR inline uint qPopulationCount(quint8 v)
Q_DECL_CONSTEXPR inline uint qPopulationCount(quint16 v)
{
-#ifdef Q_CC_GNU
+#ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT
return __builtin_popcount(v);
#else
return
@@ -552,7 +560,7 @@ Q_DECL_CONSTEXPR inline uint qPopulationCount(quint16 v)
Q_DECL_CONSTEXPR inline uint qPopulationCount(quint64 v)
{
-#ifdef Q_CC_GNU
+#ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT
return __builtin_popcountll(v);
#else
return
@@ -570,6 +578,11 @@ Q_DECL_CONSTEXPR inline uint qPopulationCount(long unsigned int v)
return qPopulationCount(static_cast<quint64>(v));
}
+#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG)
+#undef QALGORITHMS_USE_BUILTIN_POPCOUNT
+#endif
+
+
QT_END_NAMESPACE
#endif // QALGORITHMS_H