Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
4.2.1
-
None
-
Incorrect Behavior
Description
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