summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2018-03-23 11:34:10 +0100
committerThiago Macieira <thiago.macieira@intel.com>2018-08-15 22:21:42 +0000
commit8dd78e8564d8c4249e85653a8119c1dd1a03d659 (patch)
treedcc1c667f99c0cdda01091b0484887448f0f121f
parent6670948fe312b656769ecdc9679f560ab9585e40 (diff)
Fix MSVC2017 compilation with enabled relaxed constexpr on 32-bit target
The problem is that qCountLeadingZeroBits is calling qPopulationCount which is only conditionally constexpr, so qCountLeadingZeroBits can only be marked constexpr if qPopulationCount is also. On MSVC2017 64bit this is not a problem because it uses builtins function in this case. (which is not constexpr, but it works because the compiler is not forced to diagnose the problem because of the "?:" operator. The error being fixed is: qalgorithms.h(847): error C3615: constexpr function 'qCountLeadingZeroBits' cannot result in a constant expression qalgorithms.h(858): note: failure was caused by call of undefined function or one not declared 'constexpr' qalgorithms.h(858): note: see usage of 'qPopulationCount' Task-number: QTBUG-67259 Change-Id: I65a3dfae12ca49394bec14ffefdd41a07fee1c32 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit c59cb9809559f0aae6be8544cb2049e41f8040e9) Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
-rw-r--r--src/corelib/tools/qalgorithms.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h
index c0f7709fec..3784ceff8b 100644
--- a/src/corelib/tools/qalgorithms.h
+++ b/src/corelib/tools/qalgorithms.h
@@ -590,6 +590,7 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NO
}
#elif defined(Q_CC_MSVC) && !defined(Q_OS_WINCE) && !defined(Q_PROCESSOR_ARM)
#define QT_POPCOUNT_CONSTEXPR
+#define QT_POPCOUNT_RELAXED_CONSTEXPR
#define QT_HAS_BUILTIN_CTZ
Q_ALWAYS_INLINE unsigned long qt_builtin_ctz(quint32 val)
{
@@ -676,6 +677,7 @@ Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW
#ifndef QT_POPCOUNT_CONSTEXPR
#define QT_POPCOUNT_CONSTEXPR Q_DECL_CONSTEXPR
+#define QT_POPCOUNT_RELAXED_CONSTEXPR Q_DECL_RELAXED_CONSTEXPR
#endif
} //namespace QAlgorithmsPrivate
@@ -819,7 +821,7 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint32 v) Q_DECL_NOT
#endif
}
-Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL_NOTHROW
+QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL_NOTHROW
{
#if defined(QT_HAS_BUILTIN_CLZ)
return v ? QAlgorithmsPrivate::qt_builtin_clz(v)-24U : 8U;
@@ -831,7 +833,7 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL_NOTH
#endif
}
-Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DECL_NOTHROW
+QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DECL_NOTHROW
{
#if defined(QT_HAS_BUILTIN_CLZS)
return v ? QAlgorithmsPrivate::qt_builtin_clzs(v) : 16U;
@@ -844,7 +846,7 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DECL_NOT
#endif
}
-Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint64 v) Q_DECL_NOTHROW
+QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint64 v) Q_DECL_NOTHROW
{
#if defined(QT_HAS_BUILTIN_CLZLL)
return v ? QAlgorithmsPrivate::qt_builtin_clzll(v) : 64U;
@@ -859,7 +861,7 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint64 v) Q_DECL_NOT
#endif
}
-Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(unsigned long v) Q_DECL_NOTHROW
+QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(unsigned long v) Q_DECL_NOTHROW
{
return qCountLeadingZeroBits(QIntegerForSizeof<long>::Unsigned(v));
}