From c5a3cfa488ec5653cb026060e2b8f8b6a702d020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 18 Apr 2013 07:19:03 +0200 Subject: [PATCH] Compile with Clang. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Tor Arne Vestbø --- src/corelib/tools/qalgorithms.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index fecb9120ebc..8337afcb9db 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(v)); } +#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) +#undef QALGORITHMS_USE_BUILTIN_POPCOUNT +#endif + + QT_END_NAMESPACE #endif // QALGORITHMS_H