Bug 39802 - std::num_get fails to parse negative zero input correctly
Summary: std::num_get fails to parse negative zero input correctly
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 4.4.1
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-17 22:26 UTC by David Ritter
Modified: 2011-03-30 19:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-04-18 01:17:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Ritter 2009-04-17 22:26:33 UTC
A call to std::num_get fails to parse negative values (specifically -0 in my example).

/** Begin Test **/
#include <cassert>
#include <locale>
#include <sstream>

int main ()
{
    unsigned long val = 1;

    std::stringbuf sb ("-0");
    std::istream is (&sb);

    std::ios_base::iostate err (std::ios_base::goodbit);

    typedef std::istreambuf_iterator<char> iter_t;

    const std::num_get<char, iter_t>& fac =
        std::use_facet<std::num_get <char> >(is.getloc ());

    fac.get (is, iter_t (), is, err, val);

    assert (is.eofbit == err && 0 == val);

    return 0;
}
/** End Test **/

Even thought this test case only exercises -0 I think the method should be able to handle any negative value.  I have noted that other implementations do not appear to exhibit this behavior.
Comment 1 Paolo Carlini 2009-04-18 01:17:12 UTC
Oops, apparently we never parsed correctly negative values for unsigned. The fix is simple.
Comment 2 paolo@gcc.gnu.org 2009-04-18 19:28:54 UTC
Subject: Bug 39802

Author: paolo
Date: Sat Apr 18 19:28:40 2009
New Revision: 146323

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146323
Log:
2009-04-18  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/39802
	* include/bits/locale_facets.tcc (num_get<>::_M_extract_int
	(_InIter, _InIter, ios_base&, ios_base::iostate&, _ValueT&)):
	Always accept negative values, for unsigned types too.
	* testsuite/22_locale/num_get/get/char/39802.cc: New.
	* testsuite/22_locale/num_get/get/wchar_t/39802.cc: Likewise.

Added:
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/char/39802.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/39802.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/locale_facets.tcc

Comment 3 Paolo Carlini 2009-04-18 19:31:14 UTC
Fixed in mainline, will be fixed in 4.4.1 too.
Comment 4 paolo@gcc.gnu.org 2009-04-21 20:27:06 UTC
Subject: Bug 39802

Author: paolo
Date: Tue Apr 21 20:26:46 2009
New Revision: 146538

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146538
Log:
2009-04-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/39802
	* include/bits/locale_facets.tcc (num_get<>::_M_extract_int
	(_InIter, _InIter, ios_base&, ios_base::iostate&, _ValueT&)):
	Always accept negative values, for unsigned types too.
	* testsuite/22_locale/num_get/get/char/39802.cc: New.
	* testsuite/22_locale/num_get/get/wchar_t/39802.cc: Likewise.

Added:
    branches/gcc-4_4-branch/libstdc++-v3/testsuite/22_locale/num_get/get/char/39802.cc
    branches/gcc-4_4-branch/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/39802.cc
Modified:
    branches/gcc-4_4-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_4-branch/libstdc++-v3/include/bits/locale_facets.tcc

Comment 5 Paolo Carlini 2009-04-21 20:27:30 UTC
Fixed.