Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73357 - in trunk: boost libs/conversion
From: antoshkka_at_[hidden]
Date: 2011-07-25 11:13:37


Author: apolukhin
Date: 2011-07-25 11:13:36 EDT (Mon, 25 Jul 2011)
New Revision: 73357
URL: http://svn.boost.org/trac/boost/changeset/73357

Log:
Fixes #5732.

* fixes compilation errors for nonconst char arrays
Text files modified:
   trunk/boost/lexical_cast.hpp | 11 ++++++++++-
   trunk/libs/conversion/lexical_cast_test.cpp | 28 ++++++++++++++++++++++++++++
   2 files changed, 38 insertions(+), 1 deletions(-)

Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp (original)
+++ trunk/boost/lexical_cast.hpp 2011-07-25 11:13:36 EDT (Mon, 25 Jul 2011)
@@ -1000,6 +1000,11 @@
         };
     }
 
+ namespace detail
+ {
+ struct do_not_construct_stringbuffer_t{};
+ }
+
     namespace detail // optimized stream wrapper
     {
         // String representation of Source has an upper limit.
@@ -1021,7 +1026,7 @@
             typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
                 RequiresStringbuffer,
                 local_stringbuffer_t,
- char
+ do_not_construct_stringbuffer_t
>::type deduced_stringbuffer_t;
 
             // A string representation of Source is written to [start, finish).
@@ -1210,13 +1215,17 @@
             bool operator<<(signed char ch) { return ((*this) << static_cast<char>(ch)); }
 #if !defined(BOOST_LCAST_NO_WCHAR_T)
             bool operator<<(wchar_t const* str) { return shl_char_array(str); }
+ bool operator<<(wchar_t * str) { return shl_char_array(str); }
 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
             bool operator<<(wchar_t ch) { return shl_char(ch); }
 #endif
 #endif
             bool operator<<(unsigned char const* ch) { return ((*this) << reinterpret_cast<char const*>(ch)); }
+ bool operator<<(unsigned char * ch) { return ((*this) << reinterpret_cast<char *>(ch)); }
             bool operator<<(signed char const* ch) { return ((*this) << reinterpret_cast<char const*>(ch)); }
+ bool operator<<(signed char * ch) { return ((*this) << reinterpret_cast<char *>(ch)); }
             bool operator<<(char const* str) { return shl_char_array(str); }
+ bool operator<<(char* str) { return shl_char_array(str); }
             bool operator<<(short n) { return shl_signed(n); }
             bool operator<<(int n) { return shl_signed(n); }
             bool operator<<(long n) { return shl_signed(n); }

Modified: trunk/libs/conversion/lexical_cast_test.cpp
==============================================================================
--- trunk/libs/conversion/lexical_cast_test.cpp (original)
+++ trunk/libs/conversion/lexical_cast_test.cpp 2011-07-25 11:13:36 EDT (Mon, 25 Jul 2011)
@@ -35,6 +35,7 @@
 
 #include <boost/type_traits/integral_promotion.hpp>
 #include <string>
+#include <vector>
 #include <memory>
 
 #if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) \
@@ -69,6 +70,7 @@
 void test_conversion_to_int();
 void test_conversion_to_double();
 void test_conversion_to_bool();
+void test_conversion_with_nonconst_char();
 void test_conversion_to_string();
 void test_conversion_from_to_wchar_t_alias();
 void test_conversion_to_pointer();
@@ -109,6 +111,7 @@
     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
     suite->add(BOOST_TEST_CASE(test_conversion_from_wchar_t));
     suite->add(BOOST_TEST_CASE(test_conversion_to_wchar_t));
@@ -199,6 +202,31 @@
         lexical_cast<int>(std::string("Test")), bad_lexical_cast);
 }
 
+void test_conversion_with_nonconst_char()
+{
+ std::vector<char> buffer;
+ buffer.push_back('1');
+ buffer.push_back('\0');
+ BOOST_CHECK_EQUAL(boost::lexical_cast<int>(&buffer[0]), 1);
+
+ std::vector<unsigned char> buffer2;
+ buffer2.push_back('1');
+ buffer2.push_back('\0');
+ BOOST_CHECK_EQUAL(boost::lexical_cast<int>(&buffer2[0]), 1);
+
+ std::vector<unsigned char> buffer3;
+ buffer3.push_back('1');
+ buffer3.push_back('\0');
+ BOOST_CHECK_EQUAL(boost::lexical_cast<int>(&buffer3[0]), 1);
+
+#ifndef BOOST_LCAST_NO_WCHAR_T
+ std::vector<wchar_t> buffer4;
+ buffer4.push_back(L'1');
+ buffer4.push_back(L'\0');
+ BOOST_CHECK_EQUAL(boost::lexical_cast<int>(&buffer4[0]), 1);
+#endif
+}
+
 void test_conversion_to_double()
 {
     BOOST_CHECK_CLOSE_FRACTION(1.0, lexical_cast<double>('1'), (std::numeric_limits<double>::epsilon()));


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