Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85160 - in branches/release: boost libs/conversion libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2013-07-25 12:29:12


Author: apolukhin
Date: 2013-07-25 12:29:11 EDT (Thu, 25 Jul 2013)
New Revision: 85160
URL: http://svn.boost.org/trac/boost/changeset/85160

Log:
Merge lexical_cast and some conversion docs and test from trunk:
* fixed int128 and uint128 conversions (fixes #8790)
* fixed warnings from Boost Inspection Report

Text files modified:
   branches/release/boost/lexical_cast.hpp | 27 +++++++++++++++------------
   branches/release/libs/conversion/cast.htm | 18 ++++++++++++------
   branches/release/libs/conversion/index.html | 15 +++++++++++++--
   branches/release/libs/conversion/numeric_cast_test.cpp | 2 +-
   branches/release/libs/conversion/test/Jamfile.v2 | 7 ++++++-
   branches/release/libs/conversion/test/implicit_cast_fail.cpp | 4 +++-
   branches/release/libs/conversion/test/lexical_cast_integral_types_test.cpp | 39 +++++++++++++++++++++++++++------------
   branches/release/libs/conversion/test/lexical_cast_to_pointer_test.cpp | 2 ++
   8 files changed, 79 insertions(+), 35 deletions(-)

Modified: branches/release/boost/lexical_cast.hpp
==============================================================================
--- branches/release/boost/lexical_cast.hpp Thu Jul 25 09:19:50 2013 (r85159)
+++ branches/release/boost/lexical_cast.hpp 2013-07-25 12:29:11 EDT (Thu, 25 Jul 2013) (r85160)
@@ -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 @@
> {};
 #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 @@
         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 @@
         {
 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
             BOOST_STATIC_ASSERT(!std::numeric_limits<T>::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<T>::is_specialized,
+ "std::numeric_limits are not specialized for integral type passed to boost::lexical_cast"
+ );
 #endif
             CharT const czero = lcast_char_constants<CharT>::zero;
             --end;
@@ -1827,7 +1831,7 @@
             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<Traits>(n, finish); return true; }
         bool operator<<(const boost::int128_type& n) { return shl_signed(n); }
 #endif
@@ -2039,7 +2043,7 @@
             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 @@
         );
     }
 #endif
-#ifndef BOOST_NO_CHAR16_T
+#ifndef BOOST_NO_CXX11_CHAR16_T
     template <typename Target>
     inline Target lexical_cast(const char16_t* chars, std::size_t count)
     {
@@ -2562,7 +2566,7 @@
         );
     }
 #endif
-#ifndef BOOST_NO_CHAR32_T
+#ifndef BOOST_NO_CXX11_CHAR32_T
     template <typename Target>
     inline Target lexical_cast(const char32_t* chars, std::size_t count)
     {
@@ -2719,7 +2723,6 @@
 
 #undef BOOST_LCAST_THROW_BAD_CAST
 #undef BOOST_LCAST_NO_WCHAR_T
-#undef BOOST_LCAST_HAS_INT128
 
 #endif // BOOST_LEXICAL_CAST_INCLUDED
 

Modified: branches/release/libs/conversion/cast.htm
==============================================================================
--- branches/release/libs/conversion/cast.htm Thu Jul 25 09:19:50 2013 (r85159)
+++ branches/release/libs/conversion/cast.htm 2013-07-25 12:29:11 EDT (Thu, 25 Jul 2013) (r85160)
@@ -10,6 +10,13 @@
     <meta name="ProgId" content="FrontPage.Editor.Document">
 
     <title>Header boost/cast.hpp Documentation</title>
+ <style>
+ .copyright
+ {
+ color: #666666;
+ font-size: small;
+ }
+ </style>
   </head>
 
   <body bgcolor="#FFFFFF" text="#000000">
@@ -131,10 +138,9 @@
                     -->June 23, 2005<!--webbot bot="Timestamp" endspan i-checksum="30348"
                     --></p>
 
- <p>&copy; 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.</p>
+ <p class="copyright">&copy; Copyright boost.org 1999.
+ 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)
+ </p>
   </body>
-</html>
\ No newline at end of file
+</html>

Modified: branches/release/libs/conversion/index.html
==============================================================================
--- branches/release/libs/conversion/index.html Thu Jul 25 09:19:50 2013 (r85159)
+++ branches/release/libs/conversion/index.html 2013-07-25 12:29:11 EDT (Thu, 25 Jul 2013) (r85160)
@@ -6,6 +6,13 @@
 <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
 <meta name="ProgId" content="FrontPage.Editor.Document">
 <title>Boost Conversion Library</title>
+<style>
+ .copyright
+ {
+ color: #666666;
+ font-size: small;
+ }
+</style>
 </head>
 
 <body bgcolor="#FFFFFF" text="#000000">
@@ -32,7 +39,11 @@
 <p>Revised <!--webbot bot="Timestamp" S-Type="EDITED"
 S-Format="%d %B, %Y" startspan -->June 23, 2005<!--webbot bot="Timestamp" endspan i-checksum="30348" -->
 </p>
-
+<p class="copyright">
+ Copyright 2001 Beman Dawes.
+ 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)
+</p>
 </body>
 
-</html>
\ No newline at end of file
+</html>

Modified: branches/release/libs/conversion/numeric_cast_test.cpp
==============================================================================
--- branches/release/libs/conversion/numeric_cast_test.cpp Thu Jul 25 09:19:50 2013 (r85159)
+++ branches/release/libs/conversion/numeric_cast_test.cpp 2013-07-25 12:29:11 EDT (Thu, 25 Jul 2013) (r85160)
@@ -48,7 +48,7 @@
     long large_negative_value = LONG_MIN;
     signed char c = 0;
 
- c = large_value; // see if compiler generates warning
+ c = static_cast<signed char>(large_value);
 
     c = numeric_cast<signed char>( small_value );
     BOOST_CHECK( c == 1 );

Modified: branches/release/libs/conversion/test/Jamfile.v2
==============================================================================
--- branches/release/libs/conversion/test/Jamfile.v2 Thu Jul 25 09:19:50 2013 (r85159)
+++ branches/release/libs/conversion/test/Jamfile.v2 2013-07-25 12:29:11 EDT (Thu, 25 Jul 2013) (r85160)
@@ -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 @@
         <toolset>gcc-4.7:<cxxflags>-ftrapv
         <toolset>gcc-4.6:<cxxflags>-ftrapv
         <toolset>clang:<cxxflags>-ftrapv
+ # default to all warnings on:
+ <warnings>all
+ # set warnings as errors for those compilers we know we get warning free:
+ <toolset>gcc:<cxxflags>-Wextra
+ <toolset>gcc:<cxxflags>-Wno-uninitialized
     ;
 
 # Thanks to Steven Watanabe for helping with <nowchar> feature

Modified: branches/release/libs/conversion/test/implicit_cast_fail.cpp
==============================================================================
--- branches/release/libs/conversion/test/implicit_cast_fail.cpp Thu Jul 25 09:19:50 2013 (r85159)
+++ branches/release/libs/conversion/test/implicit_cast_fail.cpp 2013-07-25 12:29:11 EDT (Thu, 25 Jul 2013) (r85160)
@@ -19,6 +19,8 @@
 int test_main(int, char*[])
 {
     foo x = implicit_cast<foo>("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;
 }
+

Modified: branches/release/libs/conversion/test/lexical_cast_integral_types_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_integral_types_test.cpp Thu Jul 25 09:19:50 2013 (r85159)
+++ branches/release/libs/conversion/test/lexical_cast_integral_types_test.cpp 2013-07-25 12:29:11 EDT (Thu, 25 Jul 2013) (r85160)
@@ -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_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 @@
     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 @@
     // 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<T>(must_owerflow_str), bad_lexical_cast);
         BOOST_CHECK_THROW(lexical_cast<T>(must_owerflow_negative_str), bad_lexical_cast);
@@ -557,15 +553,34 @@
 #endif
 
 
-#ifdef BOOST_LCAST_HAS_INT128
+#ifdef BOOST_HAS_INT128
+
+template <bool Specialized, class T>
+struct test_if_specialized {
+ static void test() {}
+};
+
+template <class T>
+struct test_if_specialized<true, T> {
+ static void test() {
+ test_conversion_from_to_integral_minimal<T>();
+ }
+};
+
 void test_conversion_from_to_int128()
 {
- test_conversion_from_to_integral_minimal<boost::int128_type>();
+ test_if_specialized<
+ std::numeric_limits<boost::int128_type>::is_specialized,
+ boost::int128_type
+ >::test();
 }
 
 void test_conversion_from_to_uint128()
 {
- test_conversion_from_to_integral_minimal<boost::uint128_type>();
+ test_if_specialized<
+ std::numeric_limits<boost::int128_type>::is_specialized,
+ boost::uint128_type
+ >::test();
 }
 #endif
 
@@ -602,7 +617,7 @@
     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<boost::int128_type>();
 #endif
 #endif

Modified: branches/release/libs/conversion/test/lexical_cast_to_pointer_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_to_pointer_test.cpp Thu Jul 25 09:19:50 2013 (r85159)
+++ branches/release/libs/conversion/test/lexical_cast_to_pointer_test.cpp 2013-07-25 12:29:11 EDT (Thu, 25 Jul 2013) (r85160)
@@ -17,5 +17,7 @@
 int test_main(int, char*[])
 {
     boost::lexical_cast<char*>("Hello");
+ BOOST_CHECK(false); // suppressing warning about 'boost::unit_test::{anonymous}::unit_test_log' defined but not used
     return 0;
 }
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk