Bug 30561

Summary: [DR 696] istream::operator>>(int&) broken
Product: gcc Reporter: Martin Sebor <msebor>
Component: libstdc++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: fang, gcc-bugs
Priority: P3    
Version: 4.1.0   
Target Milestone: 4.5.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2009-07-24 12:05:30

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.