Boost C++ Libraries: Ticket #4595: boost::lexical_cast throws std::bad_cast on OS X 10.6 when using _GLIBCXX_DEBUG https://svn.boost.org/trac10/ticket/4595 <p> I'm on Snow Leopard, using the default compiler i686-apple-darwin10-gcc-4.2.1 </p> <p> I compile the following test code with -D_GLIBCXX_DEBUG </p> <div class="wiki-code"><div class="code"><pre><span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">s</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">lexical_cast</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&gt;</span><span class="p">(</span><span class="n">x</span><span class="p">);</span> </pre></div></div><p> When executed, the program terminates with the output </p> <pre class="wiki">terminate called after throwing an instance of 'std::bad_cast' what(): std::bad_cast Abort trap </pre><p> The code runs fine when _GLIBCXX_DEBUG is not defined </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4595 Trac 1.4.3 Spinach <dspiciarich@…> Tue, 21 Sep 2010 21:12:49 GMT <link>https://svn.boost.org/trac10/ticket/4595#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4595#comment:1</guid> <description> <p> Have you solved this error? I'm getting a similar error </p> <pre class="wiki">terminate called after throwing an instance of 'std::bad_cast' what(): std::bad_cast Abort trap </pre><p> In the error log I see: </p> <pre class="wiki">Thread 0 Crashed: Dispatch queue: com.apple.main-thread 0 libSystem.B.dylib 0x00007fff837c33d6 __kill + 10 1 libSystem.B.dylib 0x00007fff83863972 abort + 83 2 libstdc++.6.dylib 0x00007fff826785d2 __tcf_0 + 0 3 libstdc++.6.dylib 0x00007fff82676ae1 __cxxabiv1::__terminate(void (*)()) + 11 4 libstdc++.6.dylib 0x00007fff82676b16 __cxxabiv1::__unexpected(void (*)()) + 0 5 libstdc++.6.dylib 0x00007fff82676bfc __gxx_exception_cleanup(_Unwind_Reason_Code, _Unwind_Exception*) + 0 6 libstdc++.6.dylib 0x00007fff8263293f std::__throw_bad_alloc() + 0 7 libboost_regex.dylib 0x00000001000e94b8 std::collate&lt;char&gt; const&amp; std::use_facet&lt;std::collate&lt;char&gt; &gt;(std::locale const&amp;) + 85 (locale_facets.tcc:117) 8 libboost_regex.dylib 0x00000001000c1794 boost::re_detail::cpp_regex_traits_base&lt;char&gt;::imbue(std::locale const&amp;) + 124 (cpp_regex_traits.hpp:218) 9 libboost_regex.dylib 0x00000001000f3e35 boost::re_detail::cpp_regex_traits_base&lt;char&gt;::cpp_regex_traits_base(std::locale const&amp;) + 43 (cpp_regex_traits.hpp:173) 10 libboost_regex.dylib 0x00000001000f3e83 boost::shared_ptr&lt;boost::re_detail::cpp_regex_traits_implementation&lt;char&gt; const&gt; boost::re_detail::create_cpp_regex_traits&lt;char&gt;(std::locale const&amp;) + 30 (cpp_regex_traits.hpp:852) 11 libboost_regex.dylib 0x00000001000f3eed boost::cpp_regex_traits&lt;char&gt;::cpp_regex_traits() + 35 (cpp_regex_traits.hpp:872) 12 libboost_regex.dylib 0x00000001000f3f33 boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt;::regex_traits() + 21 (regex_traits.hpp:75) 13 libboost_regex.dylib 0x00000001000f3f4b boost::regex_traits_wrapper&lt;boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::regex_traits_wrapper() + 21 (regex_traits.hpp:169) 14 libboost_regex.dylib 0x00000001000f3f8d boost::re_detail::regex_data&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::regex_data() + 63 (basic_regex.hpp:212) 15 libboost_regex.dylib 0x00000001000f4041 boost::re_detail::basic_regex_implementation&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::basic_regex_implementation() + 21 (basic_regex.hpp:248) 16 libboost_regex.dylib 0x00000001000c1815 boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::do_assign(char const*, char const*, unsigned int) + 75 (basic_regex.hpp:698) </pre><p> Any help is greatly appreciated, Spinach </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Mon, 03 Jan 2011 23:19:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4595#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4595#comment:2</guid> <description> <p> _GLIBCXX_DEBUG breaks ABI compatibility. If you use it, then Boost needs to be built with it too. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 09 May 2011 07:49:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4595#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4595#comment:3</guid> <description> <p> I still have this issue and I've built Boost with _GLIBCXX_DEBUG as well. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 09 May 2011 07:50:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4595#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4595#comment:4</guid> <description> <p> This appears to be a more likely cause: <a class="ext-link" href="http://stackoverflow.com/questions/1416096/c-debug-builds-broke-in-snow-leopard-x-code"><span class="icon">​</span>http://stackoverflow.com/questions/1416096/c-debug-builds-broke-in-snow-leopard-x-code</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Fri, 13 May 2011 06:42:59 GMT</pubDate> <title>status changed; cc, resolution set https://svn.boost.org/trac10/ticket/4595#comment:5 https://svn.boost.org/trac10/ticket/4595#comment:5 <ul> <li><strong>cc</strong> <span class="trac-author">antoshkka@…</span> added </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Thanks for the link - it explains the problem. It is not a bug of lexical_cast, it is a compiler/library bug. </p> Ticket