diff --git a/include/boost/core/bit.hpp b/include/boost/core/bit.hpp index ed9b159..c469bc8 100644 --- a/include/boost/core/bit.hpp +++ b/include/boost/core/bit.hpp @@ -329,36 +329,44 @@ BOOST_CONSTEXPR int countr_one( T x ) BOOST_NOEXCEPT #if defined(__GNUC__) || defined(__clang__) +#if defined(__clang__) && __clang_major__ * 100 + __clang_minor__ < 304 +# define BOOST_CORE_POPCOUNT_CONSTEXPR +#else +# define BOOST_CORE_POPCOUNT_CONSTEXPR BOOST_CONSTEXPR +#endif + namespace detail { -BOOST_CONSTEXPR inline int popcount_impl( unsigned char x ) BOOST_NOEXCEPT +BOOST_CORE_POPCOUNT_CONSTEXPR inline int popcount_impl( unsigned char x ) BOOST_NOEXCEPT { return __builtin_popcount( x ); } -BOOST_CONSTEXPR inline int popcount_impl( unsigned short x ) BOOST_NOEXCEPT +BOOST_CORE_POPCOUNT_CONSTEXPR inline int popcount_impl( unsigned short x ) BOOST_NOEXCEPT { return __builtin_popcount( x ); } -BOOST_CONSTEXPR inline int popcount_impl( unsigned int x ) BOOST_NOEXCEPT +BOOST_CORE_POPCOUNT_CONSTEXPR inline int popcount_impl( unsigned int x ) BOOST_NOEXCEPT { return __builtin_popcount( x ); } -BOOST_CONSTEXPR inline int popcount_impl( unsigned long x ) BOOST_NOEXCEPT +BOOST_CORE_POPCOUNT_CONSTEXPR inline int popcount_impl( unsigned long x ) BOOST_NOEXCEPT { return __builtin_popcountl( x ); } -BOOST_CONSTEXPR inline int popcount_impl( unsigned long long x ) BOOST_NOEXCEPT +BOOST_CORE_POPCOUNT_CONSTEXPR inline int popcount_impl( unsigned long long x ) BOOST_NOEXCEPT { return __builtin_popcountll( x ); } } // namespace detail +#undef BOOST_CORE_POPCOUNT_CONSTEXPR + template BOOST_CONSTEXPR int popcount( T x ) BOOST_NOEXCEPT {