[Boost-bugs] std::bad_cast with g++ 4.8.2 & Boost 1.55 on Mac OSX 10.8.5

Subject: [Boost-bugs] std::bad_cast with g++ 4.8.2 & Boost 1.55 on Mac OSX 10.8.5
From: Clem Wang (clem_at_[hidden])
Date: 2014-02-23 18:42:12


(I sent this previous but I didn't see a response. Sorry for the repeat)

I saw some other old posts on the internet about a bad cast problem with
Boost and gcc 4.4 (but not 4.3 or 4.2) and Mac OSX 10.8.5, but nothing
apparently seemed to have been resolved, at least from what I could find.

*I ran a slightly a more complex program with g++ 4.4 and boost 1.55 and I
got this more informative backtrace:*

run
Starting program: LangProfileTest
Reading symbols for shared libraries ++++................................
done
Start testLangProfile
End testLangProfile
Start testLangProfileStringInt
End testLangProfileStringInt
Start testAdd
before boost::locale::boundary::ssegment_index
libc++abi.dylib: terminate called throwing an exception

Program received signal SIGABRT, Aborted.
0x00007fff8767ad46 in __kill ()
(gdb) bt
#0 0x00007fff8767ad46 in __kill ()
#1 0x00007fff83ac5f83 in abort ()
#2 0x00007fff856f29eb in abort_message ()
#3 0x00007fff856f039a in default_terminate ()
#4 0x00007fff83ea9887 in _objc_terminate ()
#5 0x00007fff856f03c9 in safe_handler_caller ()
#6 0x00007fff856f0424 in std::terminate ()
#7 0x00007fff856f158b in __cxa_throw ()
#8 0x00007fff8bf36120 in std::__throw_bad_cast ()
#9 0x000000010001319e in
std::use_facet<boost::locale::boundary::boundary_indexing<char>
> (__loc=@0x7fff5fbff588) at locale_facets.tcc:115
#10 0x000000010001293c in
boost::locale::boundary::details::mapping_traits<__gnu_cxx::__normal_iterator<char
const*, std::string>, std::random_access_iterator_tag>::map
(t=boost::locale::boundary::character,
b={_M_current = 0x100303d98 "a"}, e={_M_current = 0x100303d99 ""},
l=@0x7fff5fbff588) at index.hpp:98
#11 0x00000001000126d9 in
boost::locale::boundary::details::mapping<__gnu_cxx::__normal_iterator<char
const*, std::string> >::mapping (this=0x7fff5fbff530,
type=boost::locale::boundary::character,
begin={_M_current = 0x100303d98 "a"}, end={_M_current = 0x100303d99 ""},
loc=@0x7fff5fbff588) at index.hpp:126
#12 0x00000001000125e3 in
boost::locale::boundary::details::mapping<__gnu_cxx::__normal_iterator<char
const*, std::string> >::mapping (this=0x7fff5fbff530,
type=boost::locale::boundary::character,
begin={_M_current = 0x100303d98 "a"}, end={_M_current = 0x100303d99 ""},
loc=@0x7fff5fbff588) at index.hpp:128
#13 0x0000000100012595 in
boost::locale::boundary::segment_index<__gnu_cxx::__normal_iterator<char
const*, std::string> >::segment_index (this=0x7fff5fbff530,
type=boost::locale::boundary::character,
begin={_M_current = 0x100303d98 "a"}, end={_M_current = 0x100303d99 ""},
loc=@0x7fff5fbff588) at index.hpp:632
#14 0x000000010000fcf3 in
boost::locale::boundary::segment_index<__gnu_cxx::__normal_iterator<char
const*, std::string> >::segment_index (this=0x7fff5fbff530,
type=boost::locale::boundary::character,
begin={_M_current = 0x100303d98 "a"}, end={_M_current = 0x100303d99 ""},
loc=@0x7fff5fbff588) at index.hpp:633

*I made a simpler version of the code and recompile (with g++ 4.8.2 and a
rebuilt boost 1.55), I got the same(?) error*:

gdb boost-test
GNU gdb 6.3.50-20050815 (Apple version gdb-1824) (Wed Feb 6 22:51:23 UTC
2013)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...
Reading symbols for shared libraries ..... done

(gdb) r
Starting program: boost-test
Reading symbols for shared libraries ++++.................................
done
terminate called after throwing an instance of 'std::bad_cast'
  what(): std::bad_cast

Program received signal SIGABRT, Aborted.
0x00007fff8767ad46 in __kill ()
(gdb) bt
#0 0x00007fff8767ad46 in __kill ()
#1 0x00007fff83ac5f83 in abort ()
#2 0x00000001000f670b in __gnu_cxx::__verbose_terminate_handler () at
../../../../libstdc++-v3/libsupc++/vterminate.cc:95
Previous frame inner to this frame (gdb could not unwind past this frame)

*The simpler code (which I didn't try to compile and run with 4.4 as I no
longer have 4.4 lying around) is:*

//////////////////////////////////
#include <string>
#include <boost/locale.hpp>
#include <locale>

using namespace boost;

int main(){

  boost::locale::generator gen;

  std::string gram = "hello world";

  boost::locale::boundary::ssegment_index
    map(boost::locale::boundary::character, // Character segmentation.
Other choices are word and sentence
    gram.begin(), // beginning of gram
    gram.end(), // end of gram
    gen("UTF-8") // Locale generation
    );
  return 0;
}
//////////////////////////////////

My actual goal (and maybe there is a much simpler way of doing this in
C++), is to count the number of unicode characters in a UTF-8 string. I
was hoping to use Boost to solve this problem. I don't fully understand
this code that generates an instance of segment_index class to be used to
loop through the UTF8 string to get a character count (not to be confused
with char count!)

As an alternative, I did find that this lightweight template library does
what I want, I am using this instead:

http://utfcpp.sourceforge.net/
#include <utf8.h>

Thanks,

-- 
Clem



This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC