diff --git a/cast.htm b/cast.htm index a1580c3..c8d14c7 100644 --- a/cast.htm +++ b/cast.htm @@ -10,6 +10,13 @@ Header boost/cast.hpp Documentation + @@ -131,10 +138,9 @@ void f( Fruit * fruit ) { -->June 23, 2005

-

© Copyright boost.org 1999. Permission to copy, use, modify, sell - and distribute this document is granted provided this copyright notice - appears in all copies. This document is provided "as is" without express - or implied warranty, and with no claim as to its suitability for any - purpose.

+ - \ No newline at end of file + diff --git a/include/boost/lexical_cast.hpp b/include/boost/lexical_cast.hpp index 66e5370..3fc0072 100644 --- a/include/boost/lexical_cast.hpp +++ b/include/boost/lexical_cast.hpp @@ -69,11 +69,6 @@ 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 @@ -316,7 +311,7 @@ namespace boost { > {}; #endif -#ifdef BOOST_LCAST_HAS_INT128 +#ifdef BOOST_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 @@ -613,7 +608,7 @@ namespace boost { BOOST_LCAST_DEF(unsigned __int64) BOOST_LCAST_DEF( __int64) #endif -#ifdef BOOST_LCAST_HAS_INT128 +#ifdef BOOST_HAS_INT128 BOOST_LCAST_DEF(boost::int128_type) BOOST_LCAST_DEF(boost::uint128_type) #endif @@ -879,6 +874,15 @@ namespace boost { { #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS BOOST_STATIC_ASSERT(!std::numeric_limits::is_signed); + + // GCC when used with flag -std=c++0x may not have std::numeric_limits + // specializations for __int128 and unsigned __int128 types. + // Try compilation with -std=gnu++0x or -std=gnu++11. + // + // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40856 + BOOST_STATIC_ASSERT_MSG(std::numeric_limits::is_specialized, + "std::numeric_limits are not specialized for integral type passed to boost::lexical_cast" + ); #endif CharT const czero = lcast_char_constants::zero; --end; @@ -1827,7 +1831,7 @@ namespace boost { bool operator<<( __int64 n) { return shl_signed(n); } #endif -#ifdef BOOST_LCAST_HAS_INT128 +#ifdef BOOST_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 @@ -2039,7 +2043,7 @@ namespace boost { bool operator>>(__int64& output) { return shr_signed(output); } #endif -#ifdef BOOST_LCAST_HAS_INT128 +#ifdef BOOST_HAS_INT128 bool operator>>(boost::uint128_type& output) { return shr_unsigned(output); } bool operator>>(boost::int128_type& output) { return shr_signed(output); } #endif @@ -2553,7 +2557,7 @@ namespace boost { ); } #endif -#ifndef BOOST_NO_CHAR16_T +#ifndef BOOST_NO_CXX11_CHAR16_T template inline Target lexical_cast(const char16_t* chars, std::size_t count) { @@ -2562,7 +2566,7 @@ namespace boost { ); } #endif -#ifndef BOOST_NO_CHAR32_T +#ifndef BOOST_NO_CXX11_CHAR32_T template inline Target lexical_cast(const char32_t* chars, std::size_t count) { @@ -2719,7 +2723,6 @@ 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/index.html b/index.html index 133680c..fbfe63a 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,13 @@ Boost Conversion Library + @@ -32,7 +39,11 @@ supplied by several headers:

Revised June 23, 2005

- + - \ No newline at end of file + 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/Jamfile.v2 b/test/Jamfile.v2 index 25980bb..c66fae7 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -1,5 +1,5 @@ # Copyright (C) 2001-2003 Douglas Gregor -# Copyright (C) 2011-2012 Antony Polukhin +# Copyright (C) 2011-2013 Antony Polukhin # # Distributed under the Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -15,6 +15,11 @@ project gcc-4.7:-ftrapv gcc-4.6:-ftrapv clang:-ftrapv + # default to all warnings on: + all + # set warnings as errors for those compilers we know we get warning free: + gcc:-Wextra + gcc:-Wno-uninitialized ; # Thanks to Steven Watanabe for helping with feature diff --git a/test/implicit_cast_fail.cpp b/test/implicit_cast_fail.cpp index a7867a1..442fa4c 100644 --- a/test/implicit_cast_fail.cpp +++ b/test/implicit_cast_fail.cpp @@ -19,6 +19,8 @@ struct foo int test_main(int, char*[]) { foo x = implicit_cast("foobar"); - (void)x; // warning suppression. + (void)x; // warning suppression. + BOOST_CHECK(false); // suppressing warning about 'boost::unit_test::{anonymous}::unit_test_log' defined but not used return 0; } + diff --git a/test/lexical_cast_integral_types_test.cpp b/test/lexical_cast_integral_types_test.cpp index 235287e..4755071 100644 --- a/test/lexical_cast_integral_types_test.cpp +++ b/test/lexical_cast_integral_types_test.cpp @@ -48,10 +48,6 @@ #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; @@ -75,7 +71,7 @@ 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 +#ifdef BOOST_HAS_INT128 void test_conversion_from_to_int128(); void test_conversion_from_to_uint128(); #endif @@ -99,7 +95,7 @@ unit_test::test_suite *init_unit_test_suite(int, char *[]) 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 +#ifdef BOOST_HAS_INT128 suite->add(BOOST_TEST_CASE(&test_conversion_from_to_int128)); suite->add(BOOST_TEST_CASE(&test_conversion_from_to_uint128)); #endif @@ -444,8 +440,8 @@ void test_conversion_from_to_integral_minimal() // test_conversion_from_to_integral_for_locale // Overflow test case from David W. Birdsall - std::string must_owerflow_str = "160000000000000000000"; - std::string must_owerflow_negative_str = "-160000000000000000000"; + std::string must_owerflow_str = (sizeof(T) < 16 ? "160000000000000000000" : "1600000000000000000000000000000000000000"); + std::string must_owerflow_negative_str = (sizeof(T) < 16 ? "-160000000000000000000" : "-1600000000000000000000000000000000000000"); for (int i = 0; i < 15; ++i) { BOOST_CHECK_THROW(lexical_cast(must_owerflow_str), bad_lexical_cast); BOOST_CHECK_THROW(lexical_cast(must_owerflow_negative_str), bad_lexical_cast); @@ -557,15 +553,34 @@ void test_conversion_from_to_ulonglong() #endif -#ifdef BOOST_LCAST_HAS_INT128 +#ifdef BOOST_HAS_INT128 + +template +struct test_if_specialized { + static void test() {} +}; + +template +struct test_if_specialized { + static void test() { + test_conversion_from_to_integral_minimal(); + } +}; + void test_conversion_from_to_int128() { - test_conversion_from_to_integral_minimal(); + test_if_specialized< + std::numeric_limits::is_specialized, + boost::int128_type + >::test(); } void test_conversion_from_to_uint128() { - test_conversion_from_to_integral_minimal(); + test_if_specialized< + std::numeric_limits::is_specialized, + boost::uint128_type + >::test(); } #endif @@ -602,7 +617,7 @@ void test_integral_conversions_on_min_max() test_integral_conversions_on_min_max_impl<__int64>(); #endif -#ifdef BOOST_LCAST_HAS_INT128 +#ifdef BOOST_HAS_INT128 test_integral_conversions_on_min_max_impl(); #endif #endif diff --git a/test/lexical_cast_to_pointer_test.cpp b/test/lexical_cast_to_pointer_test.cpp index 6756146..dcd5e55 100644 --- a/test/lexical_cast_to_pointer_test.cpp +++ b/test/lexical_cast_to_pointer_test.cpp @@ -17,5 +17,7 @@ int test_main(int, char*[]) { boost::lexical_cast("Hello"); + BOOST_CHECK(false); // suppressing warning about 'boost::unit_test::{anonymous}::unit_test_log' defined but not used return 0; } +