From d82103b898d2c831ee86a17f57656cad22e99fb1 Mon Sep 17 00:00:00 2001 From: Philip Pronin Date: Thu, 1 Aug 2013 01:42:27 -0700 Subject: [PATCH] make folly/Bits.h clang-compatible Summary: In clang (as of 3.2) intrinsics aren't `constexpr`. Test Plan: fbconfig folly/test:bits_test && fbmake opt -j32 fbconfig --clang folly/test:bits_test && fbmake opt -j32 Reviewed By: lucian@fb.com FB internal diff: D910310 --- folly/Bits.h | 25 ++++++++++++++++--------- folly/test/BitsTest.cpp | 2 ++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/folly/Bits.h b/folly/Bits.h index 2b522524..6b2fef76 100644 --- a/folly/Bits.h +++ b/folly/Bits.h @@ -61,6 +61,13 @@ #error GCC required #endif +#ifndef __clang__ +#define FOLLY_INTRINSIC_CONSTEXPR constexpr +#else +// Unlike GCC, in Clang (as of 3.2) intrinsics aren't constexpr. +#define FOLLY_INTRINSIC_CONSTEXPR const +#endif + #ifndef FOLLY_NO_CONFIG #include "folly/folly-config.h" #endif @@ -86,7 +93,7 @@ namespace folly { // Generate overloads for findFirstSet as wrappers around // appropriate ffs, ffsl, ffsll gcc builtins template -inline constexpr +inline FOLLY_INTRINSIC_CONSTEXPR typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && @@ -97,7 +104,7 @@ typename std::enable_if< } template -inline constexpr +inline FOLLY_INTRINSIC_CONSTEXPR typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && @@ -109,7 +116,7 @@ typename std::enable_if< } template -inline constexpr +inline FOLLY_INTRINSIC_CONSTEXPR typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && @@ -121,7 +128,7 @@ typename std::enable_if< } template -inline constexpr +inline FOLLY_INTRINSIC_CONSTEXPR typename std::enable_if< (std::is_integral::value && std::is_signed::value), unsigned int>::type @@ -135,7 +142,7 @@ typename std::enable_if< // findLastSet: return the 1-based index of the highest bit set // for x > 0, findLastSet(x) == 1 + floor(log2(x)) template -inline constexpr +inline FOLLY_INTRINSIC_CONSTEXPR typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && @@ -146,7 +153,7 @@ typename std::enable_if< } template -inline constexpr +inline FOLLY_INTRINSIC_CONSTEXPR typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && @@ -158,7 +165,7 @@ typename std::enable_if< } template -inline constexpr +inline FOLLY_INTRINSIC_CONSTEXPR typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && @@ -170,7 +177,7 @@ typename std::enable_if< } template -inline constexpr +inline FOLLY_INTRINSIC_CONSTEXPR typename std::enable_if< (std::is_integral::value && std::is_signed::value), @@ -180,7 +187,7 @@ typename std::enable_if< } template -inline constexpr +inline FOLLY_INTRINSIC_CONSTEXPR typename std::enable_if< std::is_integral::value && std::is_unsigned::value, T>::type diff --git a/folly/test/BitsTest.cpp b/folly/test/BitsTest.cpp index 2490161b..d617caa6 100644 --- a/folly/test/BitsTest.cpp +++ b/folly/test/BitsTest.cpp @@ -24,10 +24,12 @@ using namespace folly; // Test constexpr-ness. +#ifndef __clang__ static_assert(findFirstSet(2u) == 2, "findFirstSet"); static_assert(findLastSet(2u) == 2, "findLastSet"); static_assert(nextPowTwo(2u) == 2, "nextPowTwo"); static_assert(isPowTwo(2u), "isPowTwo"); +#endif // __clang__ namespace { -- 2.34.1