public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/32422]  New: Problem reading floats with exponent marker but no exponent
@ 2007-06-20 14:15 kreckel at ginac dot de
  2007-06-20 15:54 ` [Bug libstdc++/32422] " pcarlini at suse dot de
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kreckel at ginac dot de @ 2007-06-20 14:15 UTC (permalink / raw)
  To: gcc-bugs

When reading malformed floats like "3.14e" using operator>>, it appears like
the e character is removed from the input stream but the fact that the stream
state does not signal that something went wrong.

$ cat lcast.cpp
#include <sstream>
#include <iostream>
using namespace std;

int main()
{
    stringstream buf;
    buf.str("1e");
    float r;
    buf >> r;
    cout << "float==" << r << endl;
    cout << "tellg()==" << buf.tellg() << endl;
    cout << "fail()==" << buf.fail() << endl;
}
$ g++ lcast.cpp  &&  ./a.out
float==1
tellg()==2
fail()==0

This was noticed in the context of the boost library. There,
boost::lexical_cast<float>("1e") silently return 1.0, which is surprising. E.g.
a compiler would reject float x = 1e saying "exponent has no digits" or
something along these lines.


-- 
           Summary: Problem reading floats with exponent marker but no
                    exponent
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kreckel at ginac dot de
 GCC build triplet: x86_64-suse-linux
  GCC host triplet: x86_64-suse-linux
GCC target triplet: x86_64-suse-linux


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


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

* [Bug libstdc++/32422] Problem reading floats with exponent marker but no exponent
  2007-06-20 14:15 [Bug libstdc++/32422] New: Problem reading floats with exponent marker but no exponent kreckel at ginac dot de
  2007-06-20 15:54 ` [Bug libstdc++/32422] " pcarlini at suse dot de
@ 2007-06-20 15:54 ` pcarlini at suse dot de
  2008-08-19 17:51 ` paolo dot carlini at oracle dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pcarlini at suse dot de @ 2007-06-20 15:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pcarlini at suse dot de  2007-06-20 15:53 -------
This is a known behavior (we even have testcases for it): the issue is that
(for C++03 at least) we definitely want consistency with "C" scanf, and the
latter in many implementations behaves "incorrectly". See this glibc PR of
mine:

  http://sources.redhat.com/bugzilla/show_bug.cgi?id=1765

We can reconsider the issue in the C++0x context, not earlier than that.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-06-20 15:53:53
               date|                            |


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


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

* [Bug libstdc++/32422] Problem reading floats with exponent marker but no exponent
  2007-06-20 14:15 [Bug libstdc++/32422] New: Problem reading floats with exponent marker but no exponent kreckel at ginac dot de
@ 2007-06-20 15:54 ` pcarlini at suse dot de
  2007-06-20 15:54 ` pcarlini at suse dot de
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pcarlini at suse dot de @ 2007-06-20 15:54 UTC (permalink / raw)
  To: gcc-bugs



-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |SUSPENDED


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


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

* [Bug libstdc++/32422] Problem reading floats with exponent marker but no exponent
  2007-06-20 14:15 [Bug libstdc++/32422] New: Problem reading floats with exponent marker but no exponent kreckel at ginac dot de
  2007-06-20 15:54 ` [Bug libstdc++/32422] " pcarlini at suse dot de
  2007-06-20 15:54 ` pcarlini at suse dot de
@ 2008-08-19 17:51 ` paolo dot carlini at oracle dot com
  2008-09-22 17:27 ` paolo dot carlini at oracle dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-08-19 17:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from paolo dot carlini at oracle dot com  2008-08-19 17:49 -------
*** Bug 37160 has been marked as a duplicate of this bug. ***


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jm at bourguet dot org


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


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

* [Bug libstdc++/32422] Problem reading floats with exponent marker but no exponent
  2007-06-20 14:15 [Bug libstdc++/32422] New: Problem reading floats with exponent marker but no exponent kreckel at ginac dot de
                   ` (2 preceding siblings ...)
  2008-08-19 17:51 ` paolo dot carlini at oracle dot com
@ 2008-09-22 17:27 ` paolo dot carlini at oracle dot com
  2008-09-23  0:48 ` paolo at gcc dot gnu dot org
  2008-09-23  0:50 ` paolo dot carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-09-22 17:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2008-09-22 17:25 -------
I'm fixing this, together with DR 23.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |paolo dot carlini at oracle
                   |dot org                     |dot com
             Status|SUSPENDED                   |ASSIGNED


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


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

* [Bug libstdc++/32422] Problem reading floats with exponent marker but no exponent
  2007-06-20 14:15 [Bug libstdc++/32422] New: Problem reading floats with exponent marker but no exponent kreckel at ginac dot de
                   ` (3 preceding siblings ...)
  2008-09-22 17:27 ` paolo dot carlini at oracle dot com
@ 2008-09-23  0:48 ` paolo at gcc dot gnu dot org
  2008-09-23  0:50 ` paolo dot carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo at gcc dot gnu dot org @ 2008-09-23  0:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from paolo at gcc dot gnu dot org  2008-09-23 00:47 -------
Subject: Bug 32422

Author: paolo
Date: Tue Sep 23 00:47:02 2008
New Revision: 140574

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140574
Log:
2008-09-23  Paolo Carlini  <paolo.carlini@oracle.com>

        PR libstdc++/32422, DR 23 [Ready in R60]
        * config/locale/gnu/c_locale.cc (__convert_to_v(const char*, float&,
        ios_base::iostate&, const __c_locale&), __convert_to_v(const char*,
        double&, ios_base::iostate&, const __c_locale&), __convert_to_v(const
        char*, long double&, ios_base::iostate&, const __c_locale&)): Implement
        DR 23 and deal correctly with broken exponents.
        * config/locale/generic/c_locale.cc (__convert_to_v(const char*,
        float&, ios_base::iostate&, const __c_locale&), __convert_to_v(const
        char*, double&, ios_base::iostate&, const __c_locale&),
        __convert_to_v(const char*, long double&, ios_base::iostate&, const
        __c_locale&)): Likewise.
        * include/bits/locale_facets.tcc (num_get<>::_M_extract_int(_InIter,
        _InIter, ios_base&, ios_base::iostate&, _ValueT&)): Likewise.
        (num_get<>::_M_extract_float(_InIter, _InIter, ios_base&,
        ios_base::iostate&, string&): Change grouping check to set instead of
        OR failbit; do not check for eofbit here...
        (num_get<>::do_get(iter_type, iter_type, ios_base&,
        ios_base::iostate&, float&), num_get<>::do_get(iter_type, iter_type,
        ios_base&, ios_base::iostate&, double&), num_get<>::do_get(iter_type,
        iter_type, ios_base&, ios_base::iostate&, long double&),
        num_get<>::__do_get(iter_type, iter_type, ios_base&,
        ios_base::iostate&, double&)): ... do it here instead.
        (num_get<>::do_get(iter_type, iter_type, ios_base&,
        ios_base::iostate&, bool&)): Implement DR 23.
        (num_get<>::do_get(iter_type, iter_type, ios_base&,
        ios_base::iostate&, void*&)): Adjust.
        * doc/xml/manual/intro.xml: Add and entry for DR 23.
        * testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc:
        Adjust.
        * testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc:
        Likewise.
        * testsuite/22_locale/num_get/get/wchar_t/22131.cc: Likewise.
        * testsuite/22_locale/num_get/get/wchar_t/10.cc: Likewise.
        * testsuite/22_locale/num_get/get/wchar_t/12.cc: Likewise.
        * testsuite/22_locale/num_get/get/wchar_t/15.cc: Likewise.
        * testsuite/22_locale/num_get/get/wchar_t/16.cc: Likewise.
        * testsuite/22_locale/num_get/get/char/22131.cc: Likewise.
        * testsuite/22_locale/num_get/get/char/10.cc: Likewise.
        * testsuite/22_locale/num_get/get/char/12.cc: Likewise.
        * testsuite/22_locale/num_get/get/char/15.cc: Likewise.
        * testsuite/22_locale/num_get/get/char/16.cc: Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/config/locale/generic/c_locale.cc
    trunk/libstdc++-v3/config/locale/gnu/c_locale.cc
    trunk/libstdc++-v3/doc/xml/manual/intro.xml
    trunk/libstdc++-v3/include/bits/locale_facets.tcc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/char/10.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/char/12.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/char/15.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/char/16.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/char/22131.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/10.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/12.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/15.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/16.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/22131.cc
   
trunk/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc
   
trunk/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc


-- 


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


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

* [Bug libstdc++/32422] Problem reading floats with exponent marker but no exponent
  2007-06-20 14:15 [Bug libstdc++/32422] New: Problem reading floats with exponent marker but no exponent kreckel at ginac dot de
                   ` (4 preceding siblings ...)
  2008-09-23  0:48 ` paolo at gcc dot gnu dot org
@ 2008-09-23  0:50 ` paolo dot carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-09-23  0:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from paolo dot carlini at oracle dot com  2008-09-23 00:49 -------
Fixed for 4.4.0.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.4.0


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


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

end of thread, other threads:[~2008-09-23  0:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-20 14:15 [Bug libstdc++/32422] New: Problem reading floats with exponent marker but no exponent kreckel at ginac dot de
2007-06-20 15:54 ` [Bug libstdc++/32422] " pcarlini at suse dot de
2007-06-20 15:54 ` pcarlini at suse dot de
2008-08-19 17:51 ` paolo dot carlini at oracle dot com
2008-09-22 17:27 ` paolo dot carlini at oracle dot com
2008-09-23  0:48 ` paolo at gcc dot gnu dot org
2008-09-23  0:50 ` paolo dot carlini at oracle dot com

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).