mirror of
https://github.com/boostorg/conversion.git
synced 2025-08-02 14:04:28 +02:00
Merge lexical_cast and some conversion docs and test from trunk:
* fixed int128 and uint128 conversions (fixes #8790) * fixed warnings from Boost Inspection Report [SVN r85160]
This commit is contained in:
18
cast.htm
18
cast.htm
@@ -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 @@ void f( Fruit * fruit ) {
|
||||
-->June 23, 2005<!--webbot bot="Timestamp" endspan i-checksum="30348"
|
||||
--></p>
|
||||
|
||||
<p>© 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">© Copyright boost.org 1999.
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@@ -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<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 @@ 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<Traits>(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 <typename Target>
|
||||
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 <typename Target>
|
||||
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
|
||||
|
||||
|
15
index.html
15
index.html
@@ -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 @@ supplied by several headers:</p>
|
||||
<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 <a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
@@ -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<signed char>(large_value);
|
||||
|
||||
c = numeric_cast<signed char>( small_value );
|
||||
BOOST_CHECK( c == 1 );
|
||||
|
@@ -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
|
||||
<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
|
||||
|
@@ -19,6 +19,8 @@ struct foo
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -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<T>(must_owerflow_str), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<T>(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 <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 @@ 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<boost::int128_type>();
|
||||
#endif
|
||||
#endif
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user