
| Key: |
STDCXX-1032
|
| Type: |
Bug
|
| Status: |
Open
|
| Priority: |
Minor
|
| Assignee: |
Unassigned
|
| Reporter: |
Martin Sebor
|
| Votes: |
0
|
| Watchers: |
0
|
|
If you were logged in you would be able to see more operations.
|
|
|
| Severity: |
Incorrect Behavior
|
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.
#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:
|
|
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.
#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:
|
Show » |
| There are no comments yet on this issue.
|
|