diff --git a/include/boost/static_string/config.hpp b/include/boost/static_string/config.hpp index fe234e5..d3e5139 100644 --- a/include/boost/static_string/config.hpp +++ b/include/boost/static_string/config.hpp @@ -41,13 +41,29 @@ #define BOOST_STATIC_STRING_IS_CONST_EVAL __builtin_is_constant_evaluated() #endif -// Can we use [[nodiscard]]? -#ifdef __has_attribute -#if __has_attribute(nodiscard) -#define BOOST_STATIC_STRING_NODISCARD [[nodiscard]] -#else -#define BOOST_STATIC_STRING_NODISCARD +// This is borrowed from Boost.JSON +// https://github.com/vinniefalco/json/blob/develop/include/boost/json/detail/config.hpp +#if defined(_MSC_VER) +#define BOOST_STATIC_STRING_NORETURN __declspec(noreturn) +#elif defined(__GNUC__) +#define BOOST_STATIC_STRING_NORETURN __attribute__ ((__noreturn__)) +#elif defined(__has_attribute) && defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x5130) +#if __has_attribute(noreturn) +#define BOOST_STATIC_STRING_NORETURN [[noreturn]] #endif +#elif defined(__has_cpp_attribute) +#if __has_cpp_attribute(noreturn) +#define BOOST_STATIC_STRING_NORETURN [[noreturn]] +#endif +#else +#define BOOST_STATIC_STRING_NORETURN +#define BOOST_STATIC_STRING_NO_NORETURN +#endif + +// Can we use [[nodiscard]]? +// KRYSTIAN TODO: these checks need to be improved +#if defined(__has_attribute) && __has_attribute(nodiscard) +#define BOOST_STATIC_STRING_NODISCARD [[nodiscard]] #else #define BOOST_STATIC_STRING_NODISCARD #endif diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index 4b6ba5b..1d0da6c 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -464,7 +464,7 @@ to_static_wstring_int_impl(Integer value) noexcept BOOST_STATIC_STRING_CPP11_CONSTEXPR inline -std::size_t +int count_digits(std::size_t value) { return value < 10 ? 1 : count_digits(value / 10) + 1; @@ -484,7 +484,7 @@ to_static_string_float_impl(double value) noexcept // the + 4 is for the decimal, 'e', // its sign, and the sign of the integral portion const int reserved_count = - (std::max)(std::size_t(2), count_digits( + (std::max)(2, count_digits( std::numeric_limits::max_exponent10)) + 4; const int precision = N > reserved_count ? N - reserved_count : 0; // switch to scientific notation @@ -510,7 +510,7 @@ to_static_string_float_impl(long double value) noexcept // the + 4 is for the decimal, 'e', // its sign, and the sign of the integral portion const int reserved_count = - (std::max)(std::size_t(2), count_digits( + (std::max)(2, count_digits( std::numeric_limits::max_exponent10)) + 4; const int precision = N > reserved_count ? N - reserved_count : 0; // switch to scientific notation @@ -545,7 +545,7 @@ to_static_wstring_float_impl(double value) noexcept // the + 4 is for the decimal, 'e', // its sign, and the sign of the integral portion const int reserved_count = - (std::max)(std::size_t(2), count_digits( + (std::max)(2, count_digits( std::numeric_limits::max_exponent10)) + 4; const int precision = N > reserved_count ? N - reserved_count : 0; // switch to scientific notation @@ -580,7 +580,7 @@ to_static_wstring_float_impl(long double value) noexcept // the + 4 is for the decimal, 'e', // its sign, and the sign of the integral portion const int reserved_count = - (std::max)(std::size_t(2), count_digits( + (std::max)(2, count_digits( std::numeric_limits::max_exponent10)) + 4; const int precision = N > reserved_count ? N - reserved_count : 0; // switch to scientific notation @@ -4215,12 +4215,16 @@ private: return term(); } + BOOST_STATIC_STRING_NORETURN basic_static_string& assign_char(value_type, std::false_type) { BOOST_STATIC_STRING_THROW( std::length_error{"max_size() == 0"}); + // This eliminates any potential warnings +#ifdef BOOST_STATIC_STRING_NO_NORETURN return *this; +#endif } // Returns the size of data read from input iterator. Read data begins at data() + size() + 1.