Bug 30561 - [DR 696] istream::operator>>(int&) broken
Summary: [DR 696] istream::operator>>(int&) broken
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-23 19:02 UTC by Martin Sebor
Modified: 2009-07-24 12:05 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-07-24 12:05:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2007-01-23 19:02:26 UTC
Here's a test case for the problem I point out in c++std-lib-17897. It shows that operator>>(int&) behaves differently (and, I claim, incorrectly) from operator>>(long&) or any other extractor except the one for short (which is
affected for the same reason).

$ cat t.cpp && g++ t.cpp -static && ./a.out
#include <cassert>
#include <locale>
#include <sstream>

struct NumPunct: std::numpunct<char>
{
    std::string do_grouping () const { return "\3"; }
    char do_thousands_sep () const { return ';'; }
};

template <class T>
T extract (const char *s)
{
    std::istringstream strm (s);
    strm.imbue (std::locale (strm.getloc (), new NumPunct));

    T x = T ();
    strm >> x;
    assert ((strm.failbit | strm.eofbit) == strm.rdstate ());
    return x;
}

int main ()
{
    assert (123L == extract<long>("1;2;3"));
    assert (123  == extract<int>("1;2;3"));
}

Assertion failed: 123 == extract<int>("1;2;3"), file t.cpp, line 26
Abort (core dumped)
Comment 1 Paolo Carlini 2009-07-24 12:05:30 UTC
The resolution of the DR is implemented in mainline.
Comment 2 Paolo Carlini 2009-07-24 12:05:45 UTC
Fixed.