Boost logo

Boost Users :

Subject: Re: [Boost-users] [String Algo] error in ireplace_first or ireplace_all with std::wstring under gcc 3.4.2 (MingW)
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-01-28 10:39:36


AMDG

Doug Swanson wrote:
> If I change the above code to use a std::wstring instead, it will
> compile, but it will crash on execution:
>
> <code>
>
> #include <cstdio>
> #include <string>
> #include <boost/algorithm/string.hpp>
>
> using namespace std;
> using namespace boost;
>
> int main( void )
> {
> wstring test = L"This is a test";
> ireplace_first( test, L"test", L"success" );
> printf( "%ws\r\n", test.c_str() );
> return 0;
> }
>
> </code>
>
> Setting a breakpoint on std::terminate() in gdb gives the following
> backtrace:
>
> <snip>
> #2 0x004021d2 in std::__throw_bad_cast() ()
> #3 0x00434c69 in std::ctype<wchar_t> const&
> std::use_facet<std::ctype<wchar_t> >(std::locale const&)
> (__loc=@0x22fe8c)
> at
> C:/Applications/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/locale_facets.tcc:112
>
> <snip>
>
> I am not competent enough with Boost to understand what the call stack
> is telling me, except that __throw_bad_cast( ) is the source of the
> crash. ireplace_all gives the same behavior as ireplace_first above.
>
> Furthermore, the problem does not arise if I use replace_first or
> replace_all instead of ireplace_first or ireplace_all. It compiles
> and runs correctly.
>
> Finally, the problem does not arise if I compile using MSVC 2008. It
> compiles and runs correctly.
>
> Does this indicate a problem with gcc (MingW) unicode support? Is
> there an easy way to circumvent it?

If I recall correctly, mingw doesn't fully support wide characters.
You might be able to work around this by adding the missing
facet to the locale, but I don't know how much work this is.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net