forked from boostorg/conversion
Update code that uses string buffers (refs #8267).
Treat cast to pointer as compile time error (refs #8334). Update documentation [SVN r83601]
This commit is contained in:
@@ -278,7 +278,9 @@ limitation of compiler options that you use.
|
|||||||
|
|
||||||
* [*boost 1.54.0 :]
|
* [*boost 1.54.0 :]
|
||||||
|
|
||||||
* Added code to convert boost::int128_type and boost::uint128_type (requires GCC 4.7 or higher).
|
* Added code to convert `boost::int128_type` and `boost::uint128_type` types (requires GCC 4.7 or higher).
|
||||||
|
* Conversions to pointers will now fail to compile, instead of throwing at runtime.
|
||||||
|
* Restored ability to get pointers to `lexical_cast` function (was broken in 1.53.0).
|
||||||
|
|
||||||
* [*boost 1.53.0 :]
|
* [*boost 1.53.0 :]
|
||||||
|
|
||||||
|
@@ -1968,35 +1968,36 @@ namespace boost {
|
|||||||
template<typename InputStreamable>
|
template<typename InputStreamable>
|
||||||
bool shr_using_base_class(InputStreamable& output)
|
bool shr_using_base_class(InputStreamable& output)
|
||||||
{
|
{
|
||||||
#if (defined _MSC_VER)
|
BOOST_STATIC_ASSERT_MSG(
|
||||||
# pragma warning( push )
|
(!boost::is_pointer<InputStreamable>::value),
|
||||||
// conditional expression is constant
|
"boost::lexical_cast can not convert to pointers"
|
||||||
# pragma warning( disable : 4127 )
|
);
|
||||||
#endif
|
|
||||||
if(is_pointer<InputStreamable>::value)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
|
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
|
||||||
// If you have compilation error at this point, than your STL library
|
BOOST_STATIC_ASSERT_MSG((boost::is_same<char, CharT>::value),
|
||||||
// unsupports such conversions. Try updating it.
|
"boost::lexical_cast can not convert, because your STL library does not "
|
||||||
BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
|
"support such conversions. Try updating it."
|
||||||
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BOOST_NO_STRINGSTREAM)
|
#if defined(BOOST_NO_STRINGSTREAM)
|
||||||
std::istrstream stream(start, finish - start);
|
std::istrstream stream(start, finish - start);
|
||||||
#elif defined(BOOST_NO_STD_LOCALE)
|
#else
|
||||||
|
|
||||||
|
#if defined(BOOST_NO_STD_LOCALE)
|
||||||
std::istringstream stream;
|
std::istringstream stream;
|
||||||
#else
|
#else
|
||||||
std::basic_istringstream<CharT, Traits> stream;
|
std::basic_istringstream<CharT, Traits> stream;
|
||||||
#endif
|
#endif // BOOST_NO_STD_LOCALE
|
||||||
static_cast<unlocked_but_t*>(stream.rdbuf())
|
|
||||||
->setbuf(start, finish - start);
|
unlocked_but_t buf;
|
||||||
|
buf.setbuf(start, finish - start);
|
||||||
|
dynamic_cast<std::basic_ios<CharT, Traits>&>(stream).rdbuf(&buf);
|
||||||
|
#endif // BOOST_NO_STRINGSTREAM
|
||||||
|
|
||||||
stream.unsetf(std::ios::skipws);
|
stream.unsetf(std::ios::skipws);
|
||||||
lcast_set_precision(stream, static_cast<InputStreamable*>(0));
|
lcast_set_precision(stream, static_cast<InputStreamable*>(0));
|
||||||
#if (defined _MSC_VER)
|
|
||||||
# pragma warning( pop )
|
|
||||||
#endif
|
|
||||||
return stream >> output &&
|
return stream >> output &&
|
||||||
stream.get() ==
|
stream.get() ==
|
||||||
#if defined(__GNUC__) && (__GNUC__<3) && defined(BOOST_NO_STD_WSTRING)
|
#if defined(__GNUC__) && (__GNUC__<3) && defined(BOOST_NO_STD_WSTRING)
|
||||||
|
@@ -67,7 +67,6 @@ void test_conversion_to_bool();
|
|||||||
void test_conversion_with_nonconst_char();
|
void test_conversion_with_nonconst_char();
|
||||||
void test_conversion_to_string();
|
void test_conversion_to_string();
|
||||||
void test_conversion_from_to_wchar_t_alias();
|
void test_conversion_from_to_wchar_t_alias();
|
||||||
void test_conversion_to_pointer();
|
|
||||||
void test_conversion_from_wchar_t();
|
void test_conversion_from_wchar_t();
|
||||||
void test_conversion_to_wchar_t();
|
void test_conversion_to_wchar_t();
|
||||||
void test_conversion_from_wstring();
|
void test_conversion_from_wstring();
|
||||||
@@ -100,7 +99,6 @@ unit_test::test_suite *init_unit_test_suite(int, char *[])
|
|||||||
suite->add(BOOST_TEST_CASE(test_conversion_to_double));
|
suite->add(BOOST_TEST_CASE(test_conversion_to_double));
|
||||||
suite->add(BOOST_TEST_CASE(test_conversion_to_bool));
|
suite->add(BOOST_TEST_CASE(test_conversion_to_bool));
|
||||||
suite->add(BOOST_TEST_CASE(test_conversion_from_to_wchar_t_alias));
|
suite->add(BOOST_TEST_CASE(test_conversion_from_to_wchar_t_alias));
|
||||||
suite->add(BOOST_TEST_CASE(test_conversion_to_pointer));
|
|
||||||
suite->add(BOOST_TEST_CASE(test_conversion_to_string));
|
suite->add(BOOST_TEST_CASE(test_conversion_to_string));
|
||||||
suite->add(BOOST_TEST_CASE(test_conversion_with_nonconst_char));
|
suite->add(BOOST_TEST_CASE(test_conversion_with_nonconst_char));
|
||||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||||
@@ -312,14 +310,6 @@ void test_conversion_from_to_wchar_t_alias()
|
|||||||
BOOST_CHECK_EQUAL(std::string("123"), lexical_cast<std::string>(123ul));
|
BOOST_CHECK_EQUAL(std::string("123"), lexical_cast<std::string>(123ul));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion_to_pointer()
|
|
||||||
{
|
|
||||||
BOOST_CHECK_THROW(lexical_cast<char *>("Test"), bad_lexical_cast);
|
|
||||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
|
||||||
BOOST_CHECK_THROW(lexical_cast<wchar_t *>("Test"), bad_lexical_cast);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_conversion_from_wchar_t()
|
void test_conversion_from_wchar_t()
|
||||||
{
|
{
|
||||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||||
|
@@ -55,5 +55,6 @@ test-suite conversion
|
|||||||
[ run lexical_cast_integral_types_test.cpp ]
|
[ run lexical_cast_integral_types_test.cpp ]
|
||||||
[ run lexical_cast_stream_detection_test.cpp ]
|
[ run lexical_cast_stream_detection_test.cpp ]
|
||||||
[ run lexical_cast_stream_traits_test.cpp ]
|
[ run lexical_cast_stream_traits_test.cpp ]
|
||||||
|
[ compile-fail lexical_cast_to_pointer_test.cpp ]
|
||||||
;
|
;
|
||||||
|
|
||||||
|
21
test/lexical_cast_to_pointer_test.cpp
Normal file
21
test/lexical_cast_to_pointer_test.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// // Unit test for boost::lexical_cast.
|
||||||
|
//
|
||||||
|
// See http://www.boost.org for most recent version, including documentation.
|
||||||
|
//
|
||||||
|
// Copyright Antony Polukhin, 2013.
|
||||||
|
//
|
||||||
|
// 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).
|
||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/type.hpp>
|
||||||
|
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
int test_main(int, char*[])
|
||||||
|
{
|
||||||
|
boost::lexical_cast<char*>("Hello");
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user