This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: UTF-16 streams
- From: Tom Cook <tom dot k dot cook at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 5 Feb 2015 10:08:02 +1030
- Subject: Re: UTF-16 streams
- Authentication-results: sourceware.org; auth=none
- References: <CAFSh4UxRKt1=gVs7mui0nynTdGWv6rRJmEAtymAdAttmSr0gRA at mail dot gmail dot com>
A more specific question: is providing a specialisation of std::ctype
(ie std::ctype<char16_t>) the right way to fix this?
On Wed, Feb 4, 2015 at 5:37 PM, Tom Cook <tom.k.cook@gmail.com> wrote:
> Hi,
>
> I was a bit surprised to find that this doesn't work:
>
> #include <sstream>
> #include <string>
>
> int main() {
> std::basic_stringstream<char16_t> ss;
> std::basic_string<char16_t> s(u"Hello, world.");
> ss << s;
> ss >> s;
> }
>
> Specifically, the last line of main causes a std::bad_cast to be
> thrown, with the following stack trace:
>
> (gdb) bt
> #0 0x00007ffff7b2cea0 in __cxa_throw () from
> /usr/lib/x86_64-linux-gnu/libstdc++.so.6
> #1 0x00007ffff7b832e2 in std::__throw_bad_cast() ()
> from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
> #2 0x0000000000403840 in std::__check_facet<std::ctype<char16_t> > (__f=0x0)
> at /usr/include/c++/4.8/bits/basic_ios.h:49
> #3 0x0000000000402899 in std::basic_istream<char16_t,
> std::char_traits<char16_t> >::sentry::sentry (this=0x7fffffffdbc7,
> __in=..., __noskip=false)
> at /usr/include/c++/4.8/bits/istream.tcc:60
> #4 0x0000000000401b31 in std::operator>><char16_t,
> std::char_traits<char16_t>, std::allocator<char16_t> > (__in=...,
> __str=u"Hello, world")
> at /usr/include/c++/4.8/bits/basic_string.tcc:1009
> #5 0x000000000040139d in main () at test2.cc:8
>
> (This is for GCC 4.8; 4.9 gives similar results).
>
> AFAICT this is due to missing character traits for char16_t - have I
> got that right?
>
> Is this expected behaviour? Is it relatively straightforward to patch
> this so that it works? Could someone give me a pointer in the right
> direction?
>
> Regards,
> Tom