This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/9581: Array versions of ctype<wchar_t>::do_narrow and do_widen broken.
- From: peturr02 at ru dot is
- To: gcc-gnats at gcc dot gnu dot org
- Date: 5 Feb 2003 10:39:55 -0000
- Subject: libstdc++/9581: Array versions of ctype<wchar_t>::do_narrow and do_widen broken.
- Reply-to: peturr02 at ru dot is
>Number: 9581
>Category: libstdc++
>Synopsis: Array versions of ctype<wchar_t>::do_narrow and do_widen broken.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Feb 05 10:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: peturr02@ru.is
>Release: gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
The conversion performed by the array versions of ctype<wchar_t>::do_widen and do_narrow don't match the conversions done by the single character versions (at least in locales with multi-byte charsets).
Currently, wcsrtombs and mbsrtowcs are used to implement these functions. These functions convert between wide characters and multi-byte characters, but do_widen and do_narrow assume a one-to-one mapping between wide and narrow characters.
The documentation might also point out that these functions are mostly useless, since a one-to-one mapping usually doesn't exist.
>How-To-Repeat:
See attachment.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="ctypebug.cc"
Content-Disposition: inline; filename="ctypebug.cc"
#include <locale>
#undef NDEBUG
#include <cassert>
int main()
{
using namespace std;
locale loc ("en_US.UTF-8");
locale::global(loc);
const char* strlit = "\xc2\x80";
const wchar_t* wstrlit = L"\x80";
const ctype<wchar_t>& wct = use_facet<ctype<wchar_t> >(loc);
wchar_t wbuf[3];
wct.widen(strlit, strlit + 3, wbuf);
assert(wbuf[0] == wct.widen(strlit[0]));
assert(wbuf[1] == wct.widen(strlit[1]));
assert(wbuf[2] == wct.widen(strlit[2]));
char buf[2];
wct.narrow(wstrlit, wstrlit + 2, '\0', buf);
assert(buf[0] == wct.narrow(wstrlit[0], '\0'));
assert(buf[1] == wct.narrow(wstrlit[1], '\0'));
return 0;
}