This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/9169: filebuf output fails if codecvt<>::out returns noconv
- From: peturr02 at ru dot is
- To: gcc-gnats at gcc dot gnu dot org
- Date: 4 Jan 2003 10:23:52 -0000
- Subject: libstdc++/9169: filebuf output fails if codecvt<>::out returns noconv
- Reply-to: peturr02 at ru dot is
>Number: 9169
>Category: libstdc++
>Synopsis: filebuf output fails if codecvt<>::out returns noconv
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Jan 04 02:26:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: peturr02@ru.is
>Release: gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
If a codecvt<char, char, mbstate_t> facet that returns false from always_noconv(), but returns noconv from out() is installed in a filebuf, no output is produced.
>How-To-Repeat:
See attachment.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="noconvout.cc"
Content-Disposition: inline; filename="noconvout.cc"
#include <locale>
#include <algorithm>
#include <cstddef>
#include <cstdio>
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
class Cvt_to_upper : public codecvt<char, char, mbstate_t>
{
typedef codecvt<char, char, mbstate_t> Base;
public:
explicit Cvt_to_upper(size_t refs = 0)
: Base(refs)
{
}
protected:
result do_in(state_type&,
const extern_type* from, const extern_type* from_end,
const extern_type*& from_next,
intern_type* to, intern_type* to_end,
intern_type*& to_next) const
{
while (from < from_end && to < to_end)
*to++ = toupper(*from++);
to_next = to;
from_next = from;
return from == from_end ? ok : partial;
}
bool do_always_noconv() const throw()
{
return false;
}
};
int main()
{
locale loc1;
locale loc (loc1, new Cvt_to_upper);
char name[] = "noconvXXXXXX";
mktemp(name);
string str ("abcdefghijklmnopqrstuvwxyz");
string tmp;
{
ofstream out;
out.imbue(loc);
out.open(name);
copy(str.begin(), str.end(),
ostreambuf_iterator<char>(out));
}
{
ifstream in;
in.open(name);
copy(istreambuf_iterator<char>(in),
istreambuf_iterator<char>(),
back_inserter(tmp));
}
remove(name);
cout << tmp << endl;
assert(tmp.size() == str.size());
assert(tmp == str);
return 0;
}