UTF-16 streams

Jonathan Wakely jwakely.gcc@gmail.com
Thu Feb 5 04:41:00 GMT 2015


On 4 February 2015 at 07:07, Tom Cook 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).

Please try again with the GCC subversion trunk (GCC 5.0), I believe I
have added all the missing pieces such as ctype<char16_t>, but I'm on
holiday and can't check myself.

You can get the GCC 5.0 sources by checking them out from subversion
or downloading one of the weekly snapshots. Simple instructions for
building GCC from source are at https://gcc.gnu.org/wiki/InstallingGCC



More information about the Libstdc++ mailing list