Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85232 - in trunk: boost libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2013-08-07 07:08:02


Author: apolukhin
Date: 2013-08-07 07:08:01 EDT (Wed, 07 Aug 2013)
New Revision: 85232
URL: http://svn.boost.org/trac/boost/changeset/85232

Log:
Do not treat critcal errors as bad_lexical_cast exceptions, but if exceptions are on throw correct exception instead (refs #8966)

Text files modified:
   trunk/boost/lexical_cast.hpp | 20 ++++++++++++++++++++
   trunk/libs/conversion/test/lexical_cast_arrays_test.cpp | 6 ++++--
   2 files changed, 24 insertions(+), 2 deletions(-)

Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp Wed Aug 7 04:15:51 2013 (r85231)
+++ trunk/boost/lexical_cast.hpp 2013-08-07 07:08:01 EDT (Wed, 07 Aug 2013) (r85232)
@@ -1616,6 +1616,11 @@
                 // does not support such conversions. Try updating it.
                 BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
 #endif
+
+#ifndef BOOST_NO_EXCEPTIONS
+ out_stream.exceptions(std::ios::badbit);
+ try {
+#endif
                 bool const result = !(out_stream << input).fail();
                 const buffer_t* const p = static_cast<buffer_t*>(
                     static_cast<std::basic_streambuf<CharT, Traits>*>(out_stream.rdbuf())
@@ -1623,6 +1628,11 @@
                 start = p->pbase();
                 finish = p->pptr();
                 return result;
+#ifndef BOOST_NO_EXCEPTIONS
+ } catch (const ::std::ios_base::failure& /*f*/) {
+ return false;
+ }
+#endif
             }
 
             template <class T>
@@ -1996,6 +2006,10 @@
 #endif // BOOST_NO_STD_LOCALE
 #endif // BOOST_NO_STRINGSTREAM
 
+#ifndef BOOST_NO_EXCEPTIONS
+ stream.exceptions(std::ios::badbit);
+ try {
+#endif
                 stream.unsetf(std::ios::skipws);
                 lcast_set_precision(stream, static_cast<InputStreamable*>(0));
 
@@ -2010,6 +2024,12 @@
 #else
                 Traits::eof();
 #endif
+
+#ifndef BOOST_NO_EXCEPTIONS
+ } catch (const ::std::ios_base::failure& /*f*/) {
+ return false;
+ }
+#endif
             }
 
             template<class T>

Modified: trunk/libs/conversion/test/lexical_cast_arrays_test.cpp
==============================================================================
--- trunk/libs/conversion/test/lexical_cast_arrays_test.cpp Wed Aug 7 04:15:51 2013 (r85231)
+++ trunk/libs/conversion/test/lexical_cast_arrays_test.cpp 2013-08-07 07:08:01 EDT (Wed, 07 Aug 2013) (r85232)
@@ -222,7 +222,8 @@
         BOOST_CHECK(&res3[0] == u16ethalon);
     }
     
- BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), boost::bad_lexical_cast);
+ // Some compillers may throw std::bad_alloc here
+ BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), std::exception);
 #endif
 
 #ifdef BOOST_LC_RUNU32
@@ -248,7 +249,8 @@
         BOOST_CHECK(&res3[0] == u32ethalon);
     }
     
- BOOST_CHECK_THROW(lexical_cast<u32short_arr_type>(val), boost::bad_lexical_cast);
+ // Some compillers may throw std::bad_alloc here
+ BOOST_CHECK_THROW(lexical_cast<u32short_arr_type>(val), std::exception);
 #endif
 }
 


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