public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libstdc++/9581: Array versions of ctype<wchar_t>::do_narrow and do_widen broken.
@ 2003-02-05 10:46 peturr02
  0 siblings, 0 replies; only message in thread
From: peturr02 @ 2003-02-05 10:46 UTC (permalink / raw)
  To: gcc-gnats


>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;
}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-02-05 10:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-05 10:46 libstdc++/9581: Array versions of ctype<wchar_t>::do_narrow and do_widen broken peturr02

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).