This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
extracting -1 from stringstream to unsigned on 64bits
- From: Tomasz Mikolajczyk <tmmikolajczyk at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Mon, 07 Feb 2011 20:52:08 +0100
- Subject: extracting -1 from stringstream to unsigned on 64bits
Hi,
I noticed an unexpected behavior when I'm trying to extract an unsigned
value from the std::stringstream containing the "-1" value. Please
consider the following code (it's also attached):
#include <sstream>
#include <cassert>
#include <string>
int main(int argc, char* argv[])
{
std::string s("-1");
std::stringstream ss(s);
unsigned u = 0;
ss >> u;
assert(ss.fail());
return 0;
}
I would expect that after extraction from the stringstream object the
object has the "fail" flag set. It works this way on the 32 bit OS,
however the assertion occurs on the 64 bits OS, i.e. stringsteam is not
in the expected "fail" state.
Building:
> g++ -ggdb sstream_test.cpp -o sstream_test
Running on 32bits:
> ./sstream_test
>
Running on 64bits:
sstream_test: sstream_test.cpp:11: int main(int, char**): Assertion
`ss.fail()' failed.
Aborted
>
On 64bits OS I've running openSUSE 11.2 with native gcc in version 4.4.1
On 64bits OS I've running Debian Lenny with native gcc in version 4.3.2
Is it a known issue?
Regards,
tomaszmi
#include <sstream>
#include <cassert>
#include <string>
int main(int argc, char* argv[])
{
std::string s("-1");
std::stringstream ss(s);
unsigned u = 0;
ss >> u;
assert(ss.fail());
return 0;
}