Subject: Re: [Boost-bugs] [Boost C++ Libraries] #8124: No more exception when casting from negative number string to unsigned
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-24 07:28:33
#8124: No more exception when casting from negative number string to unsigned
------------------------------------------------+---------------------------
Reporter: Bernd Raum <braum@â¦> | Owner: apolukhin
Type: Bugs | Status: closed
Milestone: To Be Determined | Component: lexical_cast
Version: Boost 1.51.0 | Severity: Problem
Resolution: invalid | Keywords: lexical_cast unsigned
------------------------------------------------+---------------------------
Changes (by apolukhin):
* status: new => closed
* resolution: => invalid
Comment:
I'm afraid that this is not an error.
boost::lexical_cast has the behavior of std::stringstream, which uses
num_get functions of std::locale to convert numbers. If we look at the
Programming languages â C++, we'll see, that num_get uses the rules of
scanf for conversions. And in the C99 standard for unsigned input value
minus sign is optional, so if a negative number is read, no errors will
arise and the result will be the two's complement.
I do not like such behaviour, but nothing can be done.
Some code to demonstrate that lexical_cast works exactly like
std::stringstream
{{{
#include <boost/lexical_cast.hpp>
#include <sstream>
#include <assert.h>
int main() {
std::stringstream ss("-1");
unsigned int i;
ss >> i;
assert(boost::lexical_cast<unsigned int>("-1") == i);
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/8124#comment:1> 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:50:12 UTC