Fix build with clang-cl and the Intel compiler on Windows

Neither clang-cl nor the Intel compiler are able to parse the MSVC code
in a constexpr environment. For Clang, we can just use the __builtin
functions, which it does make available on Windows. For the Intel
compiler, there's no alternative, so we just don't use the _BitScanXxx
functions. It will produce slower code, though.

qalgorithms.h(587,19) :  error: variables defined in a constexpr function must be initialized
qalgorithms.h(635,12) :  note: non-constexpr function '__popcnt' cannot be used in a constant expression

etc.

Change-Id: I149e0540c00745fe8119fffd14627ded43807000
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2016-07-18 13:48:06 -07:00
parent 30eecdf6d8
commit e24f89f266

View File

@ -516,14 +516,19 @@ QT_DEPRECATED_X("Use std::binary_search") Q_OUTOFLINE_TEMPLATE RandomAccessItera
#endif // QT_DEPRECATED_SINCE(5, 2) #endif // QT_DEPRECATED_SINCE(5, 2)
#ifdef Q_CC_CLANG
// Clang had a bug where __builtin_ctz/clz/popcount were not marked as constexpr. // Clang had a bug where __builtin_ctz/clz/popcount were not marked as constexpr.
#if !defined Q_CC_CLANG || (defined __apple_build_version__ && __clang_major__ >= 7) \ # if (defined __apple_build_version__ && __clang_major__ >= 7) || (Q_CC_CLANG >= 307)
|| (Q_CC_CLANG >= 307) # define QT_HAS_CONSTEXPR_BUILTINS
# endif
#elif defined(Q_CC_MSVC) && !defined(Q_CC_INTEL) && !defined(Q_OS_WINCE) && !defined(Q_PROCESSOR_ARM)
# define QT_HAS_CONSTEXPR_BUILTINS
#elif defined(Q_CC_GNU)
# define QT_HAS_CONSTEXPR_BUILTINS # define QT_HAS_CONSTEXPR_BUILTINS
#endif #endif
#if defined QT_HAS_CONSTEXPR_BUILTINS #if defined QT_HAS_CONSTEXPR_BUILTINS
#if defined(Q_CC_GNU) #if defined(Q_CC_GNU) || defined(Q_CC_CLANG)
# define QT_HAS_BUILTIN_CTZS # define QT_HAS_BUILTIN_CTZS
Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW
{ {