This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails


In past versions of the C++ standard library, if I piped a string like "59e"
into a double, it would set the double to '59' and set position of the get
pointer to after the e.  This meant I had to check if the last char read was an
'e' and if so, back up, but that was OK.

Something changed (and I wish I could tell you when, but I don't know--probably
in my upgrade from ubuntu 9.04 to 10.04) so now when I do the same thing, the
stream parser just gets confused, sets the 'fail' bit, and sets the double to
0.  Here's a test program:


#include <sstream>
#include <iostream>
using namespace std;

int main(int argc, char** argv)
{
  stringstream withx, withe;
  withx << "59x";
  withe << "59e";
  double num;
  char cc;
  withx >> num;
  cc = withx.get();
  cout << "From the string '59x', the streamed number is " << num << ", and the
next character is '" << cc << "'" << endl;
  withe >> num;
  cc = withe.get();
  cout << "From the string '59e', the streamed number is " << num << ", and the
next character is '" << cc << "'" << endl;
  cout << "tellg: " << withe.tellg() << endl;
  cout << "tellp: " << withe.tellp() << endl;
  cout << "eof? " << withe.eof() << endl;
  cout << "fail?" << withe.fail() << endl;
  cout << "bad?" << withe.bad() << endl;
}

which outputs:


>From the string '59x', the streamed number is 59, and the next character is 'x'
>From the string '59e', the streamed number is 0, and the next character is
'&#65533;'
tellg: -1
tellp: -1
eof? 0
fail?1
bad?0

Now, ideally, parsing '59e' should behave exactly the same as parsing '59x'--it
would notice that there's no exponent, decide the 'e' wasn't part of the
number, back up, export '59', and the next result of 'get' would return 'e'. 
But barring that, going back to the old behavior of not failing and returning
59, even if the get position is post-e, would be great.

I apologize for not testing this in more recent builds--I did check the
changelog and the list of bug fixes, and didn't find this in there, though I
certainly could have missed it.


-- 
           Summary: Stream parsing of digit-then-e (with no exponent) now
                    fails
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lpsmith at u dot washington dot edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45280


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]