You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@stdcxx.apache.org by "Martin Sebor (JIRA)" <ji...@apache.org> on 2009/02/14 23:29:59 UTC

[jira] Created: (STDCXX-1032) incorrect parsing of grouping in money_get and num_get

incorrect parsing of grouping in money_get and num_get
------------------------------------------------------

                 Key: STDCXX-1032
                 URL: https://issues.apache.org/jira/browse/STDCXX-1032
             Project: C++ Standard Library
          Issue Type: Bug
          Components: 22. Localization
    Affects Versions: 4.2.1
            Reporter: Martin Sebor
            Priority: Minor
             Fix For: 4.2.2


The following program, inspired by GNU libstdc++ bug [39168 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=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.

{code: title=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;
}
{code}

Implementation survey:

{noformat}
$ # 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
{noformat}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.