From 5c8c897d30d32c20c1758eb2f9aec8f1a5b97270 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Sun, 3 Feb 2013 09:20:28 +0000 Subject: [PATCH] Fixed as many -Wconversion warnings in lexical cast and tests as possible (refs #2558) [SVN r82695] --- include/boost/lexical_cast.hpp | 30 +++++++++++++++--------------- numeric_cast_test.cpp | 2 +- test/lexical_cast_vc8_bug_test.cpp | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/boost/lexical_cast.hpp b/include/boost/lexical_cast.hpp index 0acc094..0ef3024 100644 --- a/include/boost/lexical_cast.hpp +++ b/include/boost/lexical_cast.hpp @@ -838,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; @@ -886,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; @@ -906,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 */ @@ -926,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; @@ -960,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 */ @@ -974,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; } } @@ -1192,7 +1192,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; @@ -2350,7 +2350,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) ); } }; diff --git a/numeric_cast_test.cpp b/numeric_cast_test.cpp index 7d569a4..015776d 100644 --- a/numeric_cast_test.cpp +++ b/numeric_cast_test.cpp @@ -48,7 +48,7 @@ int test_main( int , char * [] ) long large_negative_value = LONG_MIN; signed char c = 0; - c = large_value; // see if compiler generates warning + c = static_cast(large_value); c = numeric_cast( small_value ); BOOST_CHECK( c == 1 ); 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); } }