From 335c868e9b276cde41b4a94b61699294d01e2194 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Sun, 24 Feb 2013 08:31:17 +0000 Subject: [PATCH] Merge from trunk: * Silence some buggy VS warnings (fixes #7949) * Fix -Wconversion warnings (fixes #2558) * Added support for int128 conversions (fixes #7909) [SVN r83114] --- doc/lexical_cast.qbk | 132 +++++++++++++++++++++- include/boost/lexical_cast.hpp | 69 ++++++++--- test/lexical_cast_integral_types_test.cpp | 76 +++++++++++-- test/lexical_cast_vc8_bug_test.cpp | 4 +- 4 files changed, 253 insertions(+), 28 deletions(-) diff --git a/doc/lexical_cast.qbk b/doc/lexical_cast.qbk index 6fba038..ea31181 100644 --- a/doc/lexical_cast.qbk +++ b/doc/lexical_cast.qbk @@ -3,7 +3,7 @@ [version 1.0] [copyright 2000-2005 Kevlin Henney] [copyright 2006-2010 Alexander Nasonov] - [copyright 2011-2012 Antony Polukhin] + [copyright 2011-2013 Antony Polukhin] [category String and text processing] [category Miscellaneous] [license @@ -276,6 +276,10 @@ limitation of compiler options that you use. [section Changes] +* [*boost 1.54.0 :] + + * Added code to convert boost::int128_type and boost::uint128_type (requires GCC 4.7 or higher). + * [*boost 1.53.0 :] * Much better input and output streams detection for user defined types. @@ -880,6 +884,132 @@ Do not use this results to compare compilers, because tests were taken on differ ] [endsect] +[section Microsoft Visual C++ version 11.0] +[table:id Performance Table ( Microsoft Visual C++ version 11.0) +[[From->To] [lexical_cast] [std::stringstream with construction] [std::stringstream without construction][scanf/printf]] + [[ string->char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 7 ]] + [[ string->signed char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 8 ]] + [[ string->unsigned char ][ !!! *<1* !!! ][ 42 ][ 17 ][ 8 ]] + [[ string->int ][ !!! *8* !!! ][ 71 ][ 49 ][ 10 ]] + [[ string->short ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]] + [[ string->long int ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]] + [[ string->long long ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]] + [[ string->unsigned int ][ !!! *8* !!! ][ 72 ][ 46 ][ 10 ]] + [[ string->unsigned short ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]] + [[ string->unsigned long int ][ !!! *8* !!! ][ 70 ][ 45 ][ 10 ]] + [[ string->unsigned long long ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]] + [[ string->float ][ !!! *14* !!! ][ 586 ][ 559 ][ 37 ]] + [[ string->double ][ 601 ][ 618 ][ 592 ][ !!! *37* !!! ]] + [[ string->long double ][ 629 ][ 645 ][ 618 ][ !!! *37* !!! ]] + [[ string->array ][ !!! *<1* !!! ][ 52 ][ 28 ][ 11 ]] + [[ string->string ][ !!! *1* !!! ][ 59 ][ 34 ][ --- ]] + [[ string->container::string ][ !!! *2* !!! ][ 54 ][ 31 ][ --- ]] + [[ string->char ][ !!! *2* !!! ][ 50 ][ 24 ][ 9 ]] + [[ string->signed char ][ !!! *2* !!! ][ 50 ][ 24 ][ 13 ]] + [[ string->unsigned char ][ !!! *2* !!! ][ 50 ][ 24 ][ 13 ]] + [[ int->string ][ !!! *9* !!! ][ 86 ][ 59 ][ 13 ]] + [[ short->string ][ !!! *9* !!! ][ 86 ][ 59 ][ 13 ]] + [[ long int->string ][ !!! *9* !!! ][ 87 ][ 59 ][ 13 ]] + [[ long long->string ][ !!! *9* !!! ][ 88 ][ 62 ][ 13 ]] + [[ unsigned int->string ][ !!! *9* !!! ][ 87 ][ 60 ][ 13 ]] + [[ unsigned short->string ][ !!! *9* !!! ][ 91 ][ 63 ][ 13 ]] + [[ unsigned long int->string ][ !!! *9* !!! ][ 91 ][ 62 ][ 13 ]] + [[ unsigned long long->string ][ !!! *9* !!! ][ 88 ][ 60 ][ 13 ]] + [[ float->string ][ 73 ][ 167 ][ 137 ][ !!! *56* !!! ]] + [[ double->string ][ 77 ][ 176 ][ 144 ][ !!! *64* !!! ]] + [[ long double->string ][ 79 ][ 175 ][ 143 ][ !!! *63* !!! ]] + [[ char*->char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 7 ]] + [[ char*->signed char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 8 ]] + [[ char*->unsigned char ][ !!! *<1* !!! ][ 44 ][ 17 ][ 8 ]] + [[ char*->int ][ !!! *8* !!! ][ 70 ][ 47 ][ 10 ]] + [[ char*->short ][ !!! *8* !!! ][ 72 ][ 48 ][ 10 ]] + [[ char*->long int ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]] + [[ char*->long long ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]] + [[ char*->unsigned int ][ !!! *8* !!! ][ 72 ][ 46 ][ 10 ]] + [[ char*->unsigned short ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]] + [[ char*->unsigned long int ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]] + [[ char*->unsigned long long ][ !!! *8* !!! ][ 70 ][ 45 ][ 10 ]] + [[ char*->float ][ !!! *14* !!! ][ 586 ][ 560 ][ 37 ]] + [[ char*->double ][ 598 ][ 617 ][ 597 ][ !!! *40* !!! ]] + [[ char*->long double ][ 635 ][ 653 ][ 622 ][ !!! *37* !!! ]] + [[ char*->array ][ !!! *1* !!! ][ 53 ][ 28 ][ 11 ]] + [[ char*->string ][ !!! *1* !!! ][ 59 ][ 35 ][ --- ]] + [[ char*->container::string ][ !!! *3* !!! ][ 54 ][ 30 ][ --- ]] + [[ unsigned char*->char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 7 ]] + [[ unsigned char*->signed char ][ !!! *<1* !!! ][ 42 ][ 17 ][ 8 ]] + [[ unsigned char*->unsigned char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 8 ]] + [[ unsigned char*->int ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]] + [[ unsigned char*->short ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]] + [[ unsigned char*->long int ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]] + [[ unsigned char*->long long ][ !!! *8* !!! ][ 72 ][ 47 ][ 11 ]] + [[ unsigned char*->unsigned int ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]] + [[ unsigned char*->unsigned short ][ !!! *8* !!! ][ 72 ][ 48 ][ 10 ]] + [[ unsigned char*->unsigned long int ][ !!! *8* !!! ][ 71 ][ 46 ][ 10 ]] + [[ unsigned char*->unsigned long long ][ !!! *8* !!! ][ 70 ][ 45 ][ 11 ]] + [[ unsigned char*->float ][ !!! *14* !!! ][ 589 ][ 564 ][ 38 ]] + [[ unsigned char*->double ][ 601 ][ 615 ][ 588 ][ !!! *37* !!! ]] + [[ unsigned char*->long double ][ 628 ][ 644 ][ 620 ][ !!! *38* !!! ]] + [[ unsigned char*->array ][ !!! *1* !!! ][ 54 ][ 28 ][ 11 ]] + [[ unsigned char*->string ][ !!! *2* !!! ][ 59 ][ 36 ][ --- ]] + [[ unsigned char*->container::string ][ !!! *3* !!! ][ 54 ][ 30 ][ --- ]] + [[ signed char*->char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 7 ]] + [[ signed char*->signed char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 8 ]] + [[ signed char*->unsigned char ][ !!! *<1* !!! ][ 42 ][ 17 ][ 8 ]] + [[ signed char*->int ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]] + [[ signed char*->short ][ !!! *8* !!! ][ 72 ][ 48 ][ 10 ]] + [[ signed char*->long int ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]] + [[ signed char*->long long ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]] + [[ signed char*->unsigned int ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]] + [[ signed char*->unsigned short ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]] + [[ signed char*->unsigned long int ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]] + [[ signed char*->unsigned long long ][ !!! *8* !!! ][ 70 ][ 46 ][ 11 ]] + [[ signed char*->float ][ !!! *14* !!! ][ 586 ][ 562 ][ 37 ]] + [[ signed char*->double ][ 603 ][ 615 ][ 589 ][ !!! *37* !!! ]] + [[ signed char*->long double ][ 630 ][ 644 ][ 623 ][ !!! *40* !!! ]] + [[ signed char*->array ][ !!! *1* !!! ][ 54 ][ 28 ][ 11 ]] + [[ signed char*->string ][ !!! *2* !!! ][ 59 ][ 36 ][ --- ]] + [[ signed char*->container::string ][ !!! *3* !!! ][ 54 ][ 30 ][ --- ]] + [[ iterator_range->char ][ !!! *<1* !!! ][ 74 ][ 46 ][ 7 ]] + [[ iterator_range->signed char ][ !!! *<1* !!! ][ 75 ][ 46 ][ 8 ]] + [[ iterator_range->unsigned char ][ !!! *<1* !!! ][ 74 ][ 46 ][ 8 ]] + [[ iterator_range->int ][ !!! *8* !!! ][ 98 ][ 70 ][ 10 ]] + [[ iterator_range->short ][ !!! *8* !!! ][ 103 ][ 72 ][ 10 ]] + [[ iterator_range->long int ][ !!! *8* !!! ][ 111 ][ 71 ][ 10 ]] + [[ iterator_range->long long ][ !!! *8* !!! ][ 98 ][ 70 ][ 10 ]] + [[ iterator_range->unsigned int ][ !!! *7* !!! ][ 103 ][ 76 ][ 10 ]] + [[ iterator_range->unsigned short ][ !!! *8* !!! ][ 104 ][ 75 ][ 10 ]] + [[ iterator_range->unsigned long int ][ !!! *7* !!! ][ 104 ][ 71 ][ 10 ]] + [[ iterator_range->unsigned long long ][ !!! *8* !!! ][ 99 ][ 71 ][ 11 ]] + [[ iterator_range->float ][ !!! *13* !!! ][ 123 ][ 93 ][ 37 ]] + [[ iterator_range->double ][ 603 ][ 111 ][ 82 ][ !!! *38* !!! ]] + [[ iterator_range->long double ][ 629 ][ 116 ][ 83 ][ !!! *38* !!! ]] + [[ iterator_range->array ][ !!! *<1* !!! ][ 82 ][ 52 ][ 11 ]] + [[ iterator_range->string ][ !!! *2* !!! ][ 83 ][ 56 ][ --- ]] + [[ iterator_range->container::string ][ !!! *2* !!! ][ 81 ][ 53 ][ --- ]] + [[ array->char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 7 ]] + [[ array->signed char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 8 ]] + [[ array->unsigned char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 8 ]] + [[ array->int ][ !!! *8* !!! ][ 73 ][ 46 ][ 10 ]] + [[ array->short ][ !!! *8* !!! ][ 73 ][ 47 ][ 10 ]] + [[ array->long int ][ !!! *8* !!! ][ 75 ][ 48 ][ 10 ]] + [[ array->long long ][ !!! *8* !!! ][ 73 ][ 48 ][ 11 ]] + [[ array->unsigned int ][ !!! *8* !!! ][ 73 ][ 47 ][ 10 ]] + [[ array->unsigned short ][ !!! *8* !!! ][ 74 ][ 50 ][ 10 ]] + [[ array->unsigned long int ][ !!! *8* !!! ][ 71 ][ 46 ][ 10 ]] + [[ array->unsigned long long ][ !!! *8* !!! ][ 70 ][ 47 ][ 11 ]] + [[ array->float ][ !!! *14* !!! ][ 586 ][ 567 ][ 37 ]] + [[ array->double ][ 599 ][ 624 ][ 590 ][ !!! *37* !!! ]] + [[ array->long double ][ 632 ][ 643 ][ 618 ][ !!! *37* !!! ]] + [[ array->array ][ !!! *1* !!! ][ 52 ][ 28 ][ 11 ]] + [[ array->string ][ !!! *2* !!! ][ 59 ][ 34 ][ --- ]] + [[ array->container::string ][ !!! *3* !!! ][ 55 ][ 30 ][ --- ]] + [[ int->int ][ !!! *<1* !!! ][ 105 ][ 79 ][ --- ]] + [[ float->double ][ !!! *<1* !!! ][ 226 ][ 188 ][ --- ]] + [[ char->signed char ][ !!! *<1* !!! ][ 40 ][ 16 ][ --- ]] +] +[endsect] + + [/ END of section, generated by performance measuring program ] [endsect] diff --git a/include/boost/lexical_cast.hpp b/include/boost/lexical_cast.hpp index 94dbaf9..2b1d95a 100644 --- a/include/boost/lexical_cast.hpp +++ b/include/boost/lexical_cast.hpp @@ -69,6 +69,11 @@ throw_exception(bad_lexical_cast(typeid(Source), typeid(Target))) #endif +#if (defined(BOOST_LCAST_HAS_INT128) && !defined(__GNUC__)) || GCC_VERSION > 40700 +#define BOOST_LCAST_HAS_INT128 +#endif + + namespace boost { // exception used to indicate runtime lexical_cast failure @@ -310,6 +315,11 @@ namespace boost { > {}; #endif +#ifdef BOOST_LCAST_HAS_INT128 + template <> struct stream_char_common< boost::int128_type >: public boost::mpl::identity< char > {}; + template <> struct stream_char_common< boost::uint128_type >: public boost::mpl::identity< char > {}; +#endif + #if !defined(BOOST_LCAST_NO_WCHAR_T) && defined(BOOST_NO_INTRINSIC_WCHAR_T) template <> struct stream_char_common< wchar_t > @@ -602,6 +612,10 @@ namespace boost { BOOST_LCAST_DEF(unsigned __int64) BOOST_LCAST_DEF( __int64) #endif +#ifdef BOOST_LCAST_HAS_INT128 + BOOST_LCAST_DEF(boost::int128_type) + BOOST_LCAST_DEF(boost::uint128_type) +#endif #undef BOOST_LCAST_DEF @@ -824,7 +838,7 @@ namespace boost { if(group < grouping_size) { char const grp_size = grouping[group]; - last_grp_size = grp_size <= 0 ? CHAR_MAX : grp_size; + last_grp_size = grp_size <= 0 ? static_cast(CHAR_MAX) : grp_size; } left = last_grp_size; @@ -872,7 +886,7 @@ namespace boost { if (begin > end || *end < czero || *end >= czero + 10) return false; - value = *end - czero; + value = static_cast(*end - czero); --end; T multiplier = 1; bool multiplier_overflowed = false; @@ -892,17 +906,17 @@ namespace boost { { unsigned char current_grouping = 0; CharT const thousands_sep = np.thousands_sep(); - char remained = grouping[current_grouping] - 1; + char remained = static_cast(grouping[current_grouping] - 1); bool shall_we_return = true; for(;end>=begin; --end) { if (remained) { - T const multiplier_10 = multiplier * 10; + T const multiplier_10 = static_cast(multiplier * 10); if (multiplier_10 / 10 != multiplier) multiplier_overflowed = true; - T const dig_value = *end - czero; - T const new_sub_value = multiplier_10 * dig_value; + T const dig_value = static_cast(*end - czero); + T const new_sub_value = static_cast(multiplier_10 * dig_value); if (*end < czero || *end >= czero + 10 /* detecting overflow */ @@ -912,8 +926,8 @@ namespace boost { ) return false; - value += new_sub_value; - multiplier *= 10; + value = static_cast(value + new_sub_value); + multiplier = static_cast(multiplier * 10); --remained; } else { if ( !Traits::eq(*end, thousands_sep) ) //|| begin == end ) return false; @@ -946,11 +960,11 @@ namespace boost { { while ( begin <= end ) { - T const multiplier_10 = multiplier * 10; + T const multiplier_10 = static_cast(multiplier * 10); if (multiplier_10 / 10 != multiplier) multiplier_overflowed = true; - T const dig_value = *end - czero; - T const new_sub_value = multiplier_10 * dig_value; + T const dig_value = static_cast(*end - czero); + T const new_sub_value = static_cast(multiplier_10 * dig_value); if (*end < czero || *end >= czero + 10 /* detecting overflow */ @@ -960,8 +974,8 @@ namespace boost { ) return false; - value += new_sub_value; - multiplier *= 10; + value = static_cast(value + new_sub_value); + multiplier = static_cast(multiplier * 10); --end; } } @@ -1142,6 +1156,12 @@ namespace boost { namespace detail // lcast_ret_float { + +// Silence buggy MS warnings like C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data +#if defined(_MSC_VER) && (_MSC_VER == 1400) +# pragma warning(push) +# pragma warning(disable:4244) +#endif template struct mantissa_holder_type { @@ -1178,7 +1198,7 @@ namespace boost { : np.grouping() ); std::string::size_type const grouping_size = grouping.size(); - CharT const thousands_sep = grouping_size ? np.thousands_sep() : 0; + CharT const thousands_sep = static_cast(grouping_size ? np.thousands_sep() : 0); CharT const decimal_point = np.decimal_point(); bool found_grouping = false; std::string::size_type last_grouping_pos = grouping_size - 1; @@ -1383,6 +1403,10 @@ namespace boost { return true; } +// Unsilence buggy MS warnings like C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data +#if defined(_MSC_VER) && (_MSC_VER == 1400) +# pragma warning(pop) +#endif } namespace detail // stl_buf_unlocker @@ -1723,6 +1747,12 @@ namespace boost { bool operator<<(unsigned __int64 n) { start = lcast_put_unsigned(n, finish); return true; } bool operator<<( __int64 n) { return shl_signed(n); } #endif + +#ifdef BOOST_LCAST_HAS_INT128 + bool operator<<(const boost::uint128_type& n) { start = lcast_put_unsigned(n, finish); return true; } + bool operator<<(const boost::int128_type& n) { return shl_signed(n); } +#endif + bool operator<<(float val) { return shl_real_type(val, start, finish); } bool operator<<(double val) { return shl_real_type(val, start, finish); } bool operator<<(long double val) { @@ -1916,7 +1946,7 @@ namespace boost { } /************************************ OPERATORS >> ( ... ) ********************************/ - public: + public: bool operator>>(unsigned short& output) { return shr_unsigned(output); } bool operator>>(unsigned int& output) { return shr_unsigned(output); } bool operator>>(unsigned long int& output) { return shr_unsigned(output); } @@ -1930,6 +1960,12 @@ namespace boost { bool operator>>(unsigned __int64& output) { return shr_unsigned(output); } bool operator>>(__int64& output) { return shr_signed(output); } #endif + +#ifdef BOOST_LCAST_HAS_INT128 + bool operator>>(boost::uint128_type& output) { return shr_unsigned(output); } + bool operator>>(boost::int128_type& output) { return shr_signed(output); } +#endif + bool operator>>(char& output) { return shr_xchar(output); } bool operator>>(unsigned char& output) { return shr_xchar(output); } bool operator>>(signed char& output) { return shr_xchar(output); } @@ -2324,7 +2360,7 @@ namespace boost { > converter_t; return ( - arg < 0 ? 0u - converter_t::convert(0u - arg) : converter_t::convert(arg) + arg < 0 ? static_cast(0u - converter_t::convert(0u - arg)) : converter_t::convert(arg) ); } }; @@ -2563,6 +2599,7 @@ namespace boost { #undef BOOST_LCAST_THROW_BAD_CAST #undef BOOST_LCAST_NO_WCHAR_T +#undef BOOST_LCAST_HAS_INT128 #endif // BOOST_LEXICAL_CAST_INCLUDED diff --git a/test/lexical_cast_integral_types_test.cpp b/test/lexical_cast_integral_types_test.cpp index b34cdc4..c69e741 100644 --- a/test/lexical_cast_integral_types_test.cpp +++ b/test/lexical_cast_integral_types_test.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -47,6 +48,10 @@ #define BOOST_LCAST_NO_WCHAR_T #endif +#if (defined(BOOST_LCAST_HAS_INT128) && !defined(__GNUC__)) || GCC_VERSION > 40700 +#define BOOST_LCAST_HAS_INT128 +#endif + // Test all 65536 values if true: bool const lcast_test_small_integral_types_completely = false; @@ -56,6 +61,8 @@ int const lcast_integral_test_counter=500; using namespace boost; + + void test_conversion_from_to_short(); void test_conversion_from_to_ushort(); void test_conversion_from_to_int(); @@ -68,6 +75,10 @@ void test_conversion_from_to_uintmax_t(); void test_conversion_from_to_longlong(); void test_conversion_from_to_ulonglong(); #endif +#ifdef BOOST_LCAST_HAS_INT128 +void test_conversion_from_to_int128(); +void test_conversion_from_to_uint128(); +#endif void test_integral_conversions_on_min_max(); @@ -87,6 +98,10 @@ unit_test::test_suite *init_unit_test_suite(int, char *[]) #ifdef LCAST_TEST_LONGLONG suite->add(BOOST_TEST_CASE(&test_conversion_from_to_longlong)); suite->add(BOOST_TEST_CASE(&test_conversion_from_to_ulonglong)); +#endif +#ifdef BOOST_LCAST_HAS_INT128 + suite->add(BOOST_TEST_CASE(&test_conversion_from_to_int128)); + suite->add(BOOST_TEST_CASE(&test_conversion_from_to_uint128)); #endif suite->add(BOOST_TEST_CASE(&test_integral_conversions_on_min_max)); @@ -372,7 +387,7 @@ struct restore_oldloc }; template -void test_conversion_from_to_integral() +void test_conversion_from_to_integral_minimal() { char const zero = '0'; signed char const szero = '0'; @@ -438,7 +453,12 @@ void test_conversion_from_to_integral() must_owerflow_str += '0'; must_owerflow_negative_str += '0'; } +} +template +void test_conversion_from_to_integral() +{ + test_conversion_from_to_integral_minimal(); typedef std::numpunct numpunct; restore_oldloc guard; @@ -536,19 +556,57 @@ void test_conversion_from_to_ulonglong() #endif + +#ifdef BOOST_LCAST_HAS_INT128 +void test_conversion_from_to_int128() +{ + test_conversion_from_to_integral_minimal(); +} + +void test_conversion_from_to_uint128() +{ + test_conversion_from_to_integral_minimal(); +} +#endif + +template +void test_integral_conversions_on_min_max_impl() +{ + typedef SignedT signed_t; + typedef BOOST_DEDUCED_TYPENAME boost::make_unsigned::type unsigned_t; + + typedef std::numeric_limits s_limits; + typedef std::numeric_limits uns_limits; + + BOOST_CHECK_EQUAL(lexical_cast((uns_limits::max)()), (uns_limits::max)()); + BOOST_CHECK_EQUAL(lexical_cast((uns_limits::min)()), (uns_limits::min)()); + + BOOST_CHECK_EQUAL(lexical_cast((s_limits::max)()), (s_limits::max)()); + BOOST_CHECK_EQUAL(lexical_cast((uns_limits::min)()), static_cast((uns_limits::min)())); + + BOOST_CHECK_EQUAL(lexical_cast((s_limits::max)()), static_cast((s_limits::max)())); + BOOST_CHECK_EQUAL(lexical_cast((s_limits::min)()), static_cast((s_limits::min)())); +} + void test_integral_conversions_on_min_max() { - typedef std::numeric_limits int_limits; - typedef std::numeric_limits uint_limits; + test_integral_conversions_on_min_max_impl(); + test_integral_conversions_on_min_max_impl(); - BOOST_CHECK_EQUAL(lexical_cast((uint_limits::max)()), (uint_limits::max)()); - BOOST_CHECK_EQUAL(lexical_cast((uint_limits::min)()), (uint_limits::min)()); +#ifdef _MSC_VER + test_integral_conversions_on_min_max_impl(); - BOOST_CHECK_EQUAL(lexical_cast((int_limits::max)()), (int_limits::max)()); - BOOST_CHECK_EQUAL(lexical_cast((uint_limits::min)()), static_cast((uint_limits::min)())); +#if defined(BOOST_HAS_LONG_LONG) + test_integral_conversions_on_min_max_impl(); +#elif defined(BOOST_HAS_MS_INT64) + test_integral_conversions_on_min_max_impl<__int64>(); +#endif + +#ifdef BOOST_LCAST_HAS_INT128 + test_integral_conversions_on_min_max_impl(); +#endif +#endif - BOOST_CHECK_EQUAL(lexical_cast((int_limits::max)()), static_cast((int_limits::max)())); - BOOST_CHECK_EQUAL(lexical_cast((int_limits::min)()), static_cast((int_limits::min)())); } diff --git a/test/lexical_cast_vc8_bug_test.cpp b/test/lexical_cast_vc8_bug_test.cpp index 9e5ef0b..35c7403 100644 --- a/test/lexical_cast_vc8_bug_test.cpp +++ b/test/lexical_cast_vc8_bug_test.cpp @@ -34,7 +34,7 @@ void test_too_long_number(CharT zero) o << (limits::max)() << zero; s = o.str(); BOOST_CHECK_THROW(lexical_cast(s), bad_lexical_cast); - s[s.size()-1] += 9; // '0' -> '9' + s[s.size()-1] += static_cast(9); // '0' -> '9' BOOST_CHECK_THROW(lexical_cast(s), bad_lexical_cast); if(limits::is_signed) @@ -43,7 +43,7 @@ void test_too_long_number(CharT zero) o << (limits::min)() << zero; s = o.str(); BOOST_CHECK_THROW(lexical_cast(s), bad_lexical_cast); - s[s.size()-1] += 9; // '0' -> '9' + s[s.size()-1] += static_cast(9); // '0' -> '9' BOOST_CHECK_THROW(lexical_cast(s), bad_lexical_cast); } }