[Boost-bugs] [Boost C++ Libraries] #2295: Inconsistent behavior when using 64 bit integer types

Subject: [Boost-bugs] [Boost C++ Libraries] #2295: Inconsistent behavior when using 64 bit integer types
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-09-06 18:42:49


#2295: Inconsistent behavior when using 64 bit integer types
-----------------------------------------------------+----------------------
 Reporter: Hrvoje PrgeÅ¡a <hrvoje.prgesa_at_[hidden]> | Owner: nasonov
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: lexical_cast
  Version: Boost 1.36.0 | Severity: Problem
 Keywords: lexical_cast 64 uint64_t int64_t |
-----------------------------------------------------+----------------------
 1)
 Converting 64bit unsigned int to it's max value string representation and
 back results in exception (should be identity operation!):

 {{{
 boost::uint64_t max = numeric_limits<boost::uint64_t>::max();
 std::string s = lexical_cast<string>(max);
 BOOST_CHECK_EQUAL(max, lexical_cast<boost::uint64_t>(s));
 // crashes: std::bad_cast: bad lexical cast: source type value could not
 be interpreted as target
 }}}
 2) Precise conditions when the conversion will fail are not specified in
 the documentation. Throwing of bad_lexical_cast is inconsistent:
 {{{
 #define T short
 // add a digit to a min representation!
 s = lexical_cast<string, T>(numeric_limits<T>::min()) + "0";
 BOOST_CHECK_THROW(lexical_cast<T>(s), boost::exception); // throws
 s = lexical_cast<string, T>(numeric_limits<T>::min()) + "5";
 BOOST_CHECK_THROW(lexical_cast<T>(s), boost::exception); // throws

 #define T boost::int64_t
 s = lexical_cast<string, T>(numeric_limits<T>::min()) + "0";
 BOOST_CHECK_THROW(lexical_cast<T>(s), boost::exception); // DOES NOT
 throw!?!?
 s = lexical_cast<string, T>(numeric_limits<T>::min()) + "5";
 BOOST_CHECK_THROW(lexical_cast<T>(s), boost::exception); // throws
 }}}

-- 
Ticket URL: <http://svn.boost.org/trac/boost/ticket/2295>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC