From e24f89f266cee6e2473af6f66bd78f2df3a51c83 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 18 Jul 2016 13:48:06 -0700 Subject: [PATCH] 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 Reviewed-by: Thiago Macieira --- src/corelib/tools/qalgorithms.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index 6e68bc7eb1..6e472e8b22 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -516,14 +516,19 @@ QT_DEPRECATED_X("Use std::binary_search") Q_OUTOFLINE_TEMPLATE RandomAccessItera #endif // QT_DEPRECATED_SINCE(5, 2) +#ifdef Q_CC_CLANG // 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) \ - || (Q_CC_CLANG >= 307) +# if (defined __apple_build_version__ && __clang_major__ >= 7) || (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 #endif #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 Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW {