Details

[Home]

Issue of the Implementation # S0741

Brief

money_get<> reads decimal point when frac_digits return nonpositive value

Detailed Description

From the description of class moneypunct<> (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.

Nevetheless, money_get<charT>::do_get reads decimal point and digits following it, even when frac_digits() return non-positive value.

In the sample program below the stream will be read up to end (rest of stream is ""), though should be read up to decimal point (frac_digits() returns 0).

For compare, if grouping() indicates (returning, e.g., empty string) that digits grouping is disabled, then thousands separator isn't read - if it appears in the stream, then reading of the number stops.

Problem location(s) in the standard

Linux Standard Base C++ Specification 3.2, Chapter 9. Libraries, 9.1. Interfaces for libstdcxx that refers ISO/IEC 14882: 2003 Programming languages --C++, section 22.2.2.1.2

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.455");
    ss.imbue(loc);
    string digits;
    ios_base::iostate err;
    istreambuf_iterator<char> iter = 
    	use_facet<money_get<char> >(loc).get(ss, 0, false, ss, err, digits);
    
    string rest = string(iter, istreambuf_iterator<char>());
    cout << "digits is \"" << digits << "\"\n";
    cout << "rest of stream is \"" << rest << "\"\n";
    return 0;
}

Component

libstdc++

Accepted

GCC Bugzilla 38399

Status

Fixed in gcc-4.4.0

[Home]