Issue Details (XML | Word | Printable)

Key: STDCXX-1032
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Martin Sebor
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

incorrect parsing of grouping in money_get and num_get

Created: 14/Feb/09 10:28 PM   Updated: 14/Feb/09 10:28 PM
Return to search
Component/s: 22. Localization
Affects Version/s: 4.2.1
Fix Version/s: 4.2.2

Time Tracking:
Not Specified

Severity: Incorrect Behavior


 Description  « Hide
The following program, inspired by GNU libstdc++ bug 39168 , produces different/inconsistent output on each of the implementations below. The correct behavior in the first case (neither GROUPING or INPUT defined on the command line) is unclear. In the second case (both GROUPING and INPUT defined on the command line) it appears that the only implementation that behaves correctly is GNU libstdc++. In any event, it seems that the spec needs to be clarified.
z.cpp
#include <sstream>
#include <locale>
#include <cassert>
#include <climits>
#include <cstdio>

#ifndef GROUPING
const std::string grp (1, CHAR_MAX);
#else
const std::string grp (GROUPING);
#endif

#ifndef INPUT
#  define INPUT "123,456"
#endif

struct my_moneypunct: public std::moneypunct<char> {
    std::string do_grouping() const { return grp; }
};

struct my_numpunct: public std::numpunct<char> {
    std::string do_grouping() const { return grp; }
};

int main()
{
    const std::locale loc (std::locale (std::locale (), new my_moneypunct),
                           new my_numpunct);

    std::istringstream ss (INPUT);

    ss.imbue (loc);
    
    std::string x;
    std::ios::iostate ex = ss.goodbit;

    std::use_facet<std::money_get<char> >(loc).get (ss, 0, false, ss, ex, x);

    std::printf ("\"%s\": %c%c%c\n", x.c_str (),
                 ex & ss.badbit ? 'B' : '-',
                 ex & ss.eofbit ? 'E' : '-',
                 ex & ss.failbit ? 'F' : '-');

    ss.seekg (0);

    unsigned long y = 0;
    std::ios::iostate ey = ss.goodbit;
    
    std::use_facet<std::num_get<char> >(loc).get (ss, 0, ss, ey, y);

    std::printf ("%lu: %c%c%c\n", y,
                 ey & ss.badbit ? 'B' : '-',
                 ey & ss.eofbit ? 'E' : '-',
                 ey & ss.failbit ? 'F' : '-');

    return 0;
}

Implementation survey:

$ # Apache stdcxx 4.2.0, Linux x86
$    make z && ./z \
  && make z CPPOPTS="-DGROUPING='\"\003\000\", 2' -DINPUT='\"12345,678\"'" && ./z
"123": ---
123456: -EF
"12345678": -EF
12345678: -EF

$ # gcc 4.3.3, Linux x86
$    g++ z.cpp && ./a.out \
  && g++ z.cpp -DGROUPING='"\003\000", 2' -DINPUT='"12345,678"' && ./a.out
"123456": -EF
123456: -EF
"12345678": -E-
12345678: -E-

$ # Apache stdcxx 4.2.0, Linux x86
$    make z && ./z \
  && make z CPPOPTS="-DGROUPING='\"\003\000\", 2' -DINPUT='\"12345,678\"'" && ./z
"123": ---
123456: -EF
"12345678": -EF
12345678: -EF

$ # HP aCC 6.16, IPF
$    aCC z.cpp && ./a.out \
  && aCC z.cpp -DGROUPING='"\003\000", 2' -DINPUT='"12345,678"' && ./a.out 
"12345600": -E-
123456: -E-
"": -EF
0: -EF

$ # IBM XLC++ 9.0, POWER
$    xlC z.cpp && ./a.out \
  && xlC z.cpp -DGROUPING='"\003\000", 2' -DINPUT='"12345,678"' && ./a.out 
"123": ---
123456: -E-
"12345": ---
0: -EF

$ # Sun C++ 5.9 libCstd, SPARC
$    CC z.cpp && ./a.out \
  && CC z.cpp -DGROUPING='"\003\000", 2' -DINPUT='"12345,678"' && ./a.out
"12345600": -E-
123456: -E-
"": -EF
0: -EF

$ # Sun C++ 5.9 libstlport, SPARC
$    CC z.cpp -library=stlport4 && ./a.out \
  && CC z.cpp -library=stlport4 -DGROUPING='"\003\000", 2' -DINPUT='"12345,678"' && ./a.out
"123": ---
123456: -EF
"12345": ---
12345678: -EF


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.