Boost C++ Libraries: Ticket #13366: lexical_cast throws std::bad_cast https://svn.boost.org/trac10/ticket/13366 <p> lexical_cast always throws std::bad_cast exception while converting values of type std::basic_string&lt;char, ci_char_traits&gt; (where ci_char_traits is derived from std::char_traits&lt;char&gt;) to double on Linux. It works on windows though(i.e. throws boost::bad_lexcial_cast exception for bad values, and returns double for valid values). It also works on Linux with boost 1.57. I noticed there has been a change in lexical_cast implementation that causes this issue now. std::bad_cast exception is thrown here because locale associated with the stream does not has std::num_get&lt;char, std::istreambuf_iterator&lt;char, ci_char_traits&gt; &gt; &gt; facet as shown in the stack trace below. It works with std::string (std::basic_string&lt;char, std::char_traits&lt;char&gt;) &gt; ) because locale has std::num_get&lt;char, std::istreambuf_iterator&lt;char, std::char_traits&lt;char&gt;&gt; &gt; facet. </p> <p> <a class="missing ticket">#0</a> <span class="underline">cxxabiv1::</span>cxa_throw (obj=0x60b0c0, tinfo=0x60a3f0 &lt;_ZTISt8bad_cast@@GLIBCXX_3.4&gt;, </p> <blockquote> <p> dest=0x2aaaaab092e0 &lt;std::bad_cast::~bad_cast()&gt;) at ../../../../gcc-4.8.1/libstdc++-v3/libsupc++/eh_throw.cc:71 </p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1" title="#1: Bugs: boost.build causes ftjam to segfault (closed: Wont Fix)">#1</a> 0x00002aaaaab5fb62 in std::<span class="underline">throw_bad_cast () </span></p> <blockquote> <p> at ../../../../../gcc-4.8.1/libstdc++-v3/src/c++11/functexcept.cc:56 </p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2" title="#2: Bugs: list::size should be const (closed: fixed)">#2</a> 0x00000000004051bc in std::<span class="underline">check_facet&lt;std::num_get&lt;char, std::istreambuf_iterator&lt;char, ci_char_traits&gt; &gt; &gt; (</span>f=0x0) at /xxxx/xxxx/xxxx/gcc-4.8.1/include/c++/4.8.1/bits/basic_ios.h:49 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3" title="#3: Bugs: automatic conversion and overload proble (closed: fixed)">#3</a> 0x0000000000404b3f in std::basic_istream&lt;char, ci_char_traits&gt;::_M_extract&lt;double&gt; (this=0x7fffffffe000, </p> <blockquote> <p> <span class="underline">v=@0x7fffffffe228: 0) at /xxxx/xxxx/xxxx/gcc-4.8.1/include/c++/4.8.1/bits/istream.tcc:95 </span></p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4" title="#4: Bugs: any_ptr in any library documentation? (closed: Fixed)">#4</a> 0x0000000000404397 in std::basic_istream&lt;char, ci_char_traits&gt;::operator&gt;&gt; (this=0x7fffffffe000, </p> <blockquote> <p> <span class="underline">f=@0x7fffffffe228: 0) at /xxxx/xxxx/xxxx/gcc-4.8.1/include/c++/4.8.1/istream:219 </span></p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5" title="#5: Bugs: shared_ptr and self-owning objects (closed: Fixed)">#5</a> 0x0000000000403b84 in boost::detail::lexical_ostream_limited_src&lt;char, ci_char_traits&gt;::shr_using_base_class&lt;double&gt; (this=0x7fffffffe1a0, output=@0x7fffffffe228: 0) </p> <blockquote> <p> at /xxxx/xxxx/xxxx/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:600 </p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6" title="#6: Bugs: tie in utility.hpp and tuple.hpp clash. (closed: Duplicate)">#6</a> 0x0000000000403503 in boost::detail::lexical_ostream_limited_src&lt;char, ci_char_traits&gt;::float_types_converter_internal&lt;double&gt; (this=0x7fffffffe1a0, output=@0x7fffffffe228: 0) </p> <blockquote> <p> at /xxxx/xxxx/xxxx/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:744 </p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7" title="#7: Bugs: g++ 2.96 requires NO_STRINGSTREAM (closed: Fixed)">#7</a> 0x0000000000403145 in boost::detail::lexical_ostream_limited_src&lt;char, ci_char_traits&gt;::operator&gt;&gt; ( </p> <blockquote> <p> this=0x7fffffffe1a0, output=@0x7fffffffe228: 0) at /xxxx/xxxx/xxxx/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:770 </p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8" title="#8: Bugs: prop in undirected graph + out_edges (closed: Works For Me)">#8</a> 0x0000000000402cce in boost::detail::lexical_converter_impl&lt;double, std::basic_string&lt;char, ci_char_traits, std::allocator&lt;char&gt; &gt; &gt;::try_convert (arg=..., result=@0x7fffffffe228: 0) </p> <blockquote> <p> at /xxxx/xxxx/xxxx/include/boost/lexical_cast/detail/converter_lexical.hpp:485 </p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9" title="#9: Bugs: config_info ambiguity error (closed: Invalid)">#9</a> 0x0000000000402a32 in boost::conversion::detail::try_lexical_convert&lt;double, std::basic_string&lt;char, ci_char_traits, std::allocator&lt;char&gt; &gt; &gt; (arg=..., result=@0x7fffffffe228: 0) </p> <blockquote> <p> at /xxxx/xxxx/xxxx/include/boost/lexical_cast/try_lexical_convert.hpp:196 </p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/10" title="#10: Bugs: allyourbase.jam file is bad. (closed: Out of Date)">#10</a> 0x00000000004027be in boost::lexical_cast&lt;double, std::basic_string&lt;char, ci_char_traits, std::allocator&lt;char&gt; &gt; &gt; (arg=...) at /xxxx/xxxx/xxxx/include/boost/lexical_cast.hpp:41 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/11" title="#11: Bugs: why not using mt19937? (closed: Fixed)">#11</a> 0x0000000000401d7f in lexicalcast (mystr=...) at lexicalcast_test.cpp:14 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/12" title="#12: Bugs: Can't specify VertexPredicate (closed: Fixed)">#12</a> 0x0000000000401f0d in main () at lexicalcast_test.cpp:39 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13366 Trac 1.4.3 Antony Polukhin Sun, 02 May 2021 17:29:34 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/13366#comment:1 https://svn.boost.org/trac10/ticket/13366#comment:1 <ul> <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">duplicate</span> </li> </ul> <p> Moved to github <a class="ext-link" href="https://github.com/boostorg/lexical_cast/issues/46"><span class="icon">​</span>https://github.com/boostorg/lexical_cast/issues/46</a> </p> Ticket