Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83601 - in trunk: boost libs/conversion libs/conversion/doc libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2013-03-27 13:00:47


Author: apolukhin
Date: 2013-03-27 13:00:46 EDT (Wed, 27 Mar 2013)
New Revision: 83601
URL: http://svn.boost.org/trac/boost/changeset/83601

Log:
Update code that uses string buffers (refs #8267).
Treat cast to pointer as compile time error (refs #8334).
Update documentation
Added:
   trunk/libs/conversion/test/lexical_cast_to_pointer_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/lexical_cast.hpp | 35 ++++++++++++++++++-----------------
   trunk/libs/conversion/doc/lexical_cast.qbk | 4 +++-
   trunk/libs/conversion/lexical_cast_test.cpp | 10 ----------
   trunk/libs/conversion/test/Jamfile.v2 | 1 +
   4 files changed, 22 insertions(+), 28 deletions(-)

Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp (original)
+++ trunk/boost/lexical_cast.hpp 2013-03-27 13:00:46 EDT (Wed, 27 Mar 2013)
@@ -1968,35 +1968,36 @@
             template<typename InputStreamable>
             bool shr_using_base_class(InputStreamable& output)
             {
-#if (defined _MSC_VER)
-# pragma warning( push )
- // conditional expression is constant
-# pragma warning( disable : 4127 )
-#endif
- if(is_pointer<InputStreamable>::value)
- return false;
+ BOOST_STATIC_ASSERT_MSG(
+ (!boost::is_pointer<InputStreamable>::value),
+ "boost::lexical_cast can not convert to pointers"
+ );
 
 #if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
- // If you have compilation error at this point, than your STL library
- // unsupports such conversions. Try updating it.
- BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
+ BOOST_STATIC_ASSERT_MSG((boost::is_same<char, CharT>::value),
+ "boost::lexical_cast can not convert, because your STL library does not "
+ "support such conversions. Try updating it."
+ );
 #endif
 
 #if defined(BOOST_NO_STRINGSTREAM)
                 std::istrstream stream(start, finish - start);
-#elif defined(BOOST_NO_STD_LOCALE)
+#else
+
+#if defined(BOOST_NO_STD_LOCALE)
                 std::istringstream stream;
 #else
                 std::basic_istringstream<CharT, Traits> stream;
-#endif
- static_cast<unlocked_but_t*>(stream.rdbuf())
- ->setbuf(start, finish - start);
+#endif // BOOST_NO_STD_LOCALE
+
+ 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);
                 lcast_set_precision(stream, static_cast<InputStreamable*>(0));
-#if (defined _MSC_VER)
-# pragma warning( pop )
-#endif
+
                 return stream >> output &&
                     stream.get() ==
 #if defined(__GNUC__) && (__GNUC__<3) && defined(BOOST_NO_STD_WSTRING)

Modified: trunk/libs/conversion/doc/lexical_cast.qbk
==============================================================================
--- trunk/libs/conversion/doc/lexical_cast.qbk (original)
+++ trunk/libs/conversion/doc/lexical_cast.qbk 2013-03-27 13:00:46 EDT (Wed, 27 Mar 2013)
@@ -278,7 +278,9 @@
 
 * [*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 :]
 

Modified: trunk/libs/conversion/lexical_cast_test.cpp
==============================================================================
--- trunk/libs/conversion/lexical_cast_test.cpp (original)
+++ trunk/libs/conversion/lexical_cast_test.cpp 2013-03-27 13:00:46 EDT (Wed, 27 Mar 2013)
@@ -67,7 +67,6 @@
 void test_conversion_with_nonconst_char();
 void test_conversion_to_string();
 void test_conversion_from_to_wchar_t_alias();
-void test_conversion_to_pointer();
 void test_conversion_from_wchar_t();
 void test_conversion_to_wchar_t();
 void test_conversion_from_wstring();
@@ -100,7 +99,6 @@
     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_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_with_nonconst_char));
 #ifndef BOOST_LCAST_NO_WCHAR_T
@@ -312,14 +310,6 @@
     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()
 {
 #ifndef BOOST_LCAST_NO_WCHAR_T

Modified: trunk/libs/conversion/test/Jamfile.v2
==============================================================================
--- trunk/libs/conversion/test/Jamfile.v2 (original)
+++ trunk/libs/conversion/test/Jamfile.v2 2013-03-27 13:00:46 EDT (Wed, 27 Mar 2013)
@@ -55,5 +55,6 @@
     [ run lexical_cast_integral_types_test.cpp ]
     [ run lexical_cast_stream_detection_test.cpp ]
     [ run lexical_cast_stream_traits_test.cpp ]
+ [ compile-fail lexical_cast_to_pointer_test.cpp ]
   ;
 

Added: trunk/libs/conversion/test/lexical_cast_to_pointer_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/conversion/test/lexical_cast_to_pointer_test.cpp 2013-03-27 13:00:46 EDT (Wed, 27 Mar 2013)
@@ -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;
+}


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