diff --git a/include/boost/endian/detail/endian_reverse.hpp b/include/boost/endian/detail/endian_reverse.hpp index b619657..5761b2c 100644 --- a/include/boost/endian/detail/endian_reverse.hpp +++ b/include/boost/endian/detail/endian_reverse.hpp @@ -16,6 +16,20 @@ #include #include +#if defined(BOOST_ENDIAN_NO_INTRINSICS) +# if defined(BOOST_NO_CXX14_CONSTEXPR) +# define BOOST_ENDIAN_CONSTEXPR +# else +# define BOOST_ENDIAN_CONSTEXPR constexpr +# endif +#else +# if defined(BOOST_ENDIAN_CONSTEXPR_INTRINSICS) +# define BOOST_ENDIAN_CONSTEXPR BOOST_CONSTEXPR +# else +# define BOOST_ENDIAN_CONSTEXPR +# endif +#endif + namespace boost { namespace endian @@ -30,12 +44,12 @@ namespace detail // -- intrinsic approach suggested by reviewers, and by David Stone, who provided // his Boost licensed macro implementation (detail/intrinsic.hpp) -inline uint8_t endian_reverse_impl( uint8_t x ) BOOST_NOEXCEPT +inline uint8_t BOOST_CONSTEXPR endian_reverse_impl( uint8_t x ) BOOST_NOEXCEPT { return x; } -inline uint16_t endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT +inline uint16_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT { #ifdef BOOST_ENDIAN_NO_INTRINSICS @@ -48,7 +62,7 @@ inline uint16_t endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT #endif } -inline uint32_t endian_reverse_impl(uint32_t x) BOOST_NOEXCEPT +inline uint32_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl(uint32_t x) BOOST_NOEXCEPT { #ifdef BOOST_ENDIAN_NO_INTRINSICS @@ -62,7 +76,7 @@ inline uint32_t endian_reverse_impl(uint32_t x) BOOST_NOEXCEPT #endif } -inline uint64_t endian_reverse_impl(uint64_t x) BOOST_NOEXCEPT +inline uint64_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl(uint64_t x) BOOST_NOEXCEPT { #ifdef BOOST_ENDIAN_NO_INTRINSICS diff --git a/include/boost/endian/detail/intrinsic.hpp b/include/boost/endian/detail/intrinsic.hpp index f110276..d806367 100644 --- a/include/boost/endian/detail/intrinsic.hpp +++ b/include/boost/endian/detail/intrinsic.hpp @@ -18,7 +18,7 @@ #define __has_builtin(x) 0 // Compatibility with non-clang compilers #endif -#if defined(_MSC_VER) +#if defined(_MSC_VER) && ( !defined(__clang__) || defined(__c2__) ) // Microsoft documents these as being compatible since Windows 95 and specifically // lists runtime library support since Visual Studio 2003 (aka 7.1). // Clang/c2 uses the Microsoft rather than GCC intrinsics, so we check for @@ -46,6 +46,8 @@ # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x) __builtin_bswap32(x) # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x) __builtin_bswap64(x) +# define BOOST_ENDIAN_CONSTEXPR_INTRINSICS + // Linux systems provide the byteswap.h header, with #elif defined(__linux__) // don't check for obsolete forms defined(linux) and defined(__linux) on the theory that