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++/38399] New: money_get<> read decimal point when frac_digits() <= 0


>From description of moneypunct<> facet(22.2.6.3, p3):

The format of the numeric monetary value is a decimal number:

    value ::= units [ decimal-point [ digits ]] | decimal-point digits

if frac_digits() returns a positive value, or

    value ::= units

otherwise.

But the implementation of money_get<>::do_get() reads from input stream decimal
point and digits after it and write them to the result(units or digits), even
when frac_digits() return nonpositive value.

In similar situation with grouping, when grouping string indicates that
grouping shouldn't not be applied, implementation stops read when it encounters
thousands separator.

Example:

#include <locale>
#include <sstream>
#include <iostream>

using namespace std;

class my_moneypunct : public moneypunct<char>
{
protected:
    //this should disable fraction part of monetary value
    int do_frac_digits()const {return 0;}
};

int  main()
{
    locale loc(locale(), new my_moneypunct());
    stringstream ss("123.456");
    ss.imbue(loc);
    string digits;
    ios_base::iostate err;
    use_facet<money_get<char> >(loc).get(ss, 0, false, ss, err, digits);

    string rest(istreambuf_iterator<char>(ss), istreambuf_iterator<char>());
    cout << "digits is \"" << digits << "\"\n";
    cout << "rest of stream is \"" << rest << "\"\n";
    return 0;
}

[tester@Fedore8 money_get_frac_digits]$ g++ ./test.cpp && ./a.out
digits is "123456"
rest of stream is ""
[tester@Fedore8 money_get_frac_digits]$ g++ --version
g++ (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8)
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


-- 
           Summary: money_get<> read decimal point when frac_digits() <= 0
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tsyvarev at ispras dot ru


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


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