public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/45280]  New: Stream parsing of digit-then-e (with no exponent) now fails
@ 2010-08-13 20:09 lpsmith at u dot washington dot edu
  2010-08-13 20:15 ` [Bug libstdc++/45280] " paolo dot carlini at oracle dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: lpsmith at u dot washington dot edu @ 2010-08-13 20:09 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
@ 2010-08-13 20:15 ` paolo dot carlini at oracle dot com
  2010-08-13 20:23 ` lpsmith at u dot washington dot edu
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-08-13 20:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paolo dot carlini at oracle dot com  2010-08-13 20:15 -------
Yes, this is intended. We even have testcases about that.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
  2010-08-13 20:15 ` [Bug libstdc++/45280] " paolo dot carlini at oracle dot com
  2010-08-13 20:23 ` lpsmith at u dot washington dot edu
@ 2010-08-13 20:23 ` paolo dot carlini at oracle dot com
  2010-08-13 20:34 ` lpsmith at u dot washington dot edu
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-08-13 20:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2010-08-13 20:23 -------
By the way, if you read 22.2.3.1 in C++98, it's clear that 'e' is *not* just
any other character: after 'e', a sign is optional but at least a digit is
compulsory.


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
  2010-08-13 20:15 ` [Bug libstdc++/45280] " paolo dot carlini at oracle dot com
@ 2010-08-13 20:23 ` lpsmith at u dot washington dot edu
  2010-08-13 20:23 ` paolo dot carlini at oracle dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: lpsmith at u dot washington dot edu @ 2010-08-13 20:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from lpsmith at u dot washington dot edu  2010-08-13 20:22 -------
Is the reasoning explained somewhere?


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
                   ` (2 preceding siblings ...)
  2010-08-13 20:23 ` paolo dot carlini at oracle dot com
@ 2010-08-13 20:34 ` lpsmith at u dot washington dot edu
  2010-08-13 20:56 ` lpsmith at u dot washington dot edu
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: lpsmith at u dot washington dot edu @ 2010-08-13 20:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from lpsmith at u dot washington dot edu  2010-08-13 20:34 -------
Yes, exactly!  Which is why the 'e' should not be parsed at all unless there is
an optional sign and a compulsory digit following it.  The 'e' in general is
not compulsory.  '59' is a valid double.

The context is that I am parsing (among other things) chemical reactions.  It
is perfectly valid to have something like:

2EtOH -> EtOHX


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
                   ` (3 preceding siblings ...)
  2010-08-13 20:34 ` lpsmith at u dot washington dot edu
@ 2010-08-13 20:56 ` lpsmith at u dot washington dot edu
  2010-08-13 21:00 ` paolo dot carlini at oracle dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: lpsmith at u dot washington dot edu @ 2010-08-13 20:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from lpsmith at u dot washington dot edu  2010-08-13 20:56 -------
Followup:  This still fails even if you're trying to pipe it into an integer
and not a double.  Integers, as per 22.2.3.1 in C++98, do not have an optional
'e' after them.  (Though of course you could *cast* a floating point value to
an integer.)  Given that, I hope you won't mind if I reopen the bug.


-- 

lpsmith at u dot washington dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
                   ` (4 preceding siblings ...)
  2010-08-13 20:56 ` lpsmith at u dot washington dot edu
@ 2010-08-13 21:00 ` paolo dot carlini at oracle dot com
  2010-08-13 21:14 ` lpsmith at u dot washington dot edu
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-08-13 21:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from paolo dot carlini at oracle dot com  2010-08-13 21:00 -------
You are of course wrong. Parsing something like "59e" as an integer type of
course succeeds and gives "59". Really, we have *tons* of testcases about that
in the testsuite. We know what we are doing ;)


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
                   ` (5 preceding siblings ...)
  2010-08-13 21:00 ` paolo dot carlini at oracle dot com
@ 2010-08-13 21:14 ` lpsmith at u dot washington dot edu
  2010-08-13 21:21 ` paolo dot carlini at oracle dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: lpsmith at u dot washington dot edu @ 2010-08-13 21:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from lpsmith at u dot washington dot edu  2010-08-13 21:14 -------
You're right!  Sorry; I apparently jumped to a conclusion while testing (but I
did test!)

I still disagree that an 'e' with no digit following can be reasonably
construed as part of an improperly-formatted float, and think it should instead
be considered not part of the float at all, since properly-formatted floats
have both the e and the digit.  I think you are erring on the side of assuming
an error when a valid interpretation exists.


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
                   ` (6 preceding siblings ...)
  2010-08-13 21:14 ` lpsmith at u dot washington dot edu
@ 2010-08-13 21:21 ` paolo dot carlini at oracle dot com
  2010-08-13 21:40 ` lpsmith at u dot washington dot edu
  2010-08-13 21:41 ` lpsmith at u dot washington dot edu
  9 siblings, 0 replies; 11+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-08-13 21:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from paolo dot carlini at oracle dot com  2010-08-13 21:20 -------
I'm not erring. We changes this behavior on purpose, after having also checked
that *2* other, completely independent, implementations agree (ie, Dinkumware
and Roguewave).


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
                   ` (7 preceding siblings ...)
  2010-08-13 21:21 ` paolo dot carlini at oracle dot com
@ 2010-08-13 21:40 ` lpsmith at u dot washington dot edu
  2010-08-13 21:41 ` lpsmith at u dot washington dot edu
  9 siblings, 0 replies; 11+ messages in thread
From: lpsmith at u dot washington dot edu @ 2010-08-13 21:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from lpsmith at u dot washington dot edu  2010-08-13 21:40 -------
Fair enough!  I still disagree, but I guess my task now is to get Dinkumware
and Roguewave to change their implementations, and come back.  I don't suppose
you'd be swayed by Microsoft?  I didn't think so ;-)


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/45280] Stream parsing of digit-then-e (with no exponent) now fails
  2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
                   ` (8 preceding siblings ...)
  2010-08-13 21:40 ` lpsmith at u dot washington dot edu
@ 2010-08-13 21:41 ` lpsmith at u dot washington dot edu
  9 siblings, 0 replies; 11+ messages in thread
From: lpsmith at u dot washington dot edu @ 2010-08-13 21:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from lpsmith at u dot washington dot edu  2010-08-13 21:41 -------
Whoops, duh, dinkumware is ms.  Never mind, it was a dumb joke anyway.


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-08-13 21:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-13 20:09 [Bug libstdc++/45280] New: Stream parsing of digit-then-e (with no exponent) now fails lpsmith at u dot washington dot edu
2010-08-13 20:15 ` [Bug libstdc++/45280] " paolo dot carlini at oracle dot com
2010-08-13 20:23 ` lpsmith at u dot washington dot edu
2010-08-13 20:23 ` paolo dot carlini at oracle dot com
2010-08-13 20:34 ` lpsmith at u dot washington dot edu
2010-08-13 20:56 ` lpsmith at u dot washington dot edu
2010-08-13 21:00 ` paolo dot carlini at oracle dot com
2010-08-13 21:14 ` lpsmith at u dot washington dot edu
2010-08-13 21:21 ` paolo dot carlini at oracle dot com
2010-08-13 21:40 ` lpsmith at u dot washington dot edu
2010-08-13 21:41 ` lpsmith at u dot washington dot edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).