Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79797 - in trunk: boost libs/conversion
From: antoshkka_at_[hidden]
Date: 2012-07-29 14:54:25


Author: apolukhin
Date: 2012-07-29 14:54:24 EDT (Sun, 29 Jul 2012)
New Revision: 79797
URL: http://svn.boost.org/trac/boost/changeset/79797

Log:
Fix bug with volatile types (refs #7157)
Text files modified:
   trunk/boost/lexical_cast.hpp | 11 ++++++-----
   trunk/libs/conversion/lexical_cast_test.cpp | 13 +++++++++++++
   2 files changed, 19 insertions(+), 5 deletions(-)

Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp (original)
+++ trunk/boost/lexical_cast.hpp 2012-07-29 14:54:24 EDT (Sun, 29 Jul 2012)
@@ -2077,8 +2077,9 @@
             static inline Target lexical_cast_impl(const Source& arg)
             {
                 typedef BOOST_DEDUCED_TYPENAME detail::array_to_pointer_decay<Source>::type src;
+ typedef BOOST_DEDUCED_TYPENAME ::boost::remove_cv<src>::type no_cv_src;
                 typedef BOOST_DEDUCED_TYPENAME detail::stream_char<Target>::type target_char_t;
- typedef BOOST_DEDUCED_TYPENAME detail::stream_char<src>::type src_char_type;
+ typedef BOOST_DEDUCED_TYPENAME detail::stream_char<no_cv_src>::type src_char_type;
                 typedef BOOST_DEDUCED_TYPENAME detail::widest_char<
                     target_char_t, src_char_type
>::type char_type;
@@ -2095,7 +2096,7 @@
 #endif
 
                 typedef BOOST_DEDUCED_TYPENAME ::boost::detail::deduce_char_traits<
- char_type, Target, Source
+ char_type, Target, no_cv_src
>::type traits;
 
                 typedef ::boost::type_traits::ice_and<
@@ -2106,8 +2107,8 @@
> is_string_widening_required_t;
 
                 typedef ::boost::type_traits::ice_or<
- ::boost::is_integral<src>::value,
- ::boost::detail::is_this_float_conversion_optimized<src, char_type >::value,
+ ::boost::is_integral<no_cv_src>::value,
+ ::boost::detail::is_this_float_conversion_optimized<no_cv_src, char_type >::value,
                     ::boost::detail::is_char_or_wchar<src_char_type >::value
> is_source_input_optimized_t;
 
@@ -2123,7 +2124,7 @@
                
                 typedef detail::lexical_stream_limited_src<char_type, traits, requires_stringbuf > interpreter_type;
 
- typedef detail::lcast_src_length<src > lcast_src_length;
+ typedef detail::lcast_src_length<no_cv_src> lcast_src_length;
                 std::size_t const src_len = lcast_src_length::value;
                 char_type buf[src_len + 1];
                 lcast_src_length::check_coverage();

Modified: trunk/libs/conversion/lexical_cast_test.cpp
==============================================================================
--- trunk/libs/conversion/lexical_cast_test.cpp (original)
+++ trunk/libs/conversion/lexical_cast_test.cpp 2012-07-29 14:54:24 EDT (Sun, 29 Jul 2012)
@@ -73,6 +73,7 @@
 void test_conversion_to_wstring();
 void test_bad_lexical_cast();
 void test_no_whitespace_stripping();
+void test_volatile_types_conversions();
 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 void test_traits();
 void test_wtraits();
@@ -108,6 +109,7 @@
 #endif
     suite->add(BOOST_TEST_CASE(test_bad_lexical_cast));
     suite->add(BOOST_TEST_CASE(test_no_whitespace_stripping));
+ suite->add(BOOST_TEST_CASE(test_volatile_types_conversions));
 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
     suite->add(BOOST_TEST_CASE(&test_traits));
     suite->add(BOOST_TEST_CASE(&test_wtraits));
@@ -435,6 +437,17 @@
     BOOST_CHECK_THROW(lexical_cast<int>("123 "), bad_lexical_cast);
 }
 
+void test_volatile_types_conversions()
+{
+ volatile int i1 = 100000;
+ BOOST_CHECK_EQUAL("100000", boost::lexical_cast<std::string>(i1));
+
+ volatile const int i2 = 100000;
+ BOOST_CHECK_EQUAL("100000", boost::lexical_cast<std::string>(i2));
+
+ volatile const long int i3 = 1000000;
+ BOOST_CHECK_EQUAL("1000000", boost::lexical_cast<std::string>(i3));
+}
 
 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 void test_traits()


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