Boost C++ Libraries: Ticket #5106: std::bad_cast thrown in the boost::archive::basic_binary_(o|i)primitive constructor https://svn.boost.org/trac10/ticket/5106 <div class="wikipage" style="font-size: 80%"><p> Code highlighting: </p> <div class="wiki-code"><div class="code"><pre> <span class="n">std</span><span class="o">::</span><span class="n">ofstream</span> <span class="n">ofs</span><span class="p">(</span> <span class="s">&quot;./test.dat&quot;</span> <span class="p">);</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span><span class="n">archive</span><span class="o">::</span><span class="n">binary_oarchive</span> <span class="n">oa</span><span class="p">(</span> <span class="n">ofs</span> <span class="p">);</span> </pre></div></div></div><p> Tested with gcc 4.6 on MacOSX, this simple piece of code throws a std::bad_cast exception with Boost 1.45.0 </p> <p> I found a quick fix. </p> <p> Replace this : </p> <div class="wikipage" style="font-size: 80%"><p> include/boost/archive/basic_binary_oprimitive.hpp </p> <div class="wiki-code"><div class="code"><pre><span class="mi">108</span> <span class="nf">BOOST_ARCHIVE_OR_WARCHIVE_DECL</span><span class="p">(</span><span class="n">BOOST_PP_EMPTY</span><span class="p">())</span> <span class="mi">109</span> <span class="n">basic_binary_oprimitive</span><span class="p">(</span> <span class="mi">110</span> <span class="n">std</span><span class="o">::</span><span class="n">basic_streambuf</span><span class="o">&lt;</span><span class="n">Elem</span><span class="p">,</span> <span class="n">Tr</span><span class="o">&gt;</span> <span class="o">&amp;</span> <span class="n">sb</span><span class="p">,</span> <span class="mi">111</span> <span class="kt">bool</span> <span class="n">no_codecvt</span> <span class="mi">112</span> <span class="p">);</span> </pre></div></div></div><p> By this : </p> <div class="wikipage" style="font-size: 80%"><p> include/boost/archive/basic_binary_oprimitive.hpp </p> <div class="wiki-code"><div class="code"><pre><span class="mi">108</span> <span class="nf">BOOST_ARCHIVE_OR_WARCHIVE_DECL</span><span class="p">(</span><span class="n">BOOST_PP_EMPTY</span><span class="p">())</span> <span class="mi">109</span> <span class="n">basic_binary_oprimitive</span><span class="p">(</span> <span class="mi">110</span> <span class="n">std</span><span class="o">::</span><span class="n">basic_streambuf</span><span class="o">&lt;</span><span class="n">Elem</span><span class="p">,</span> <span class="n">Tr</span><span class="o">&gt;</span> <span class="o">&amp;</span> <span class="n">sb</span><span class="p">,</span> <span class="mi">111</span> <span class="kt">bool</span> <span class="n">no_codecvt</span> <span class="mi">112</span> <span class="p">)</span> <span class="o">:</span> <span class="n">m_sb</span><span class="p">(</span> <span class="n">sb</span> <span class="p">)</span> <span class="mi">113</span> <span class="err">#</span><span class="n">ifndef</span> <span class="n">BOOST_NO_STD_LOCALE</span> <span class="mi">114</span> <span class="p">,</span> <span class="n">locale_saver</span><span class="p">(</span> <span class="n">sb</span> <span class="p">)</span> <span class="mi">115</span> <span class="err">#</span><span class="n">endif</span> <span class="mi">116</span> <span class="p">{};</span> </pre></div></div></div><p> Same modifications for the file basic_binary_<strong>i</strong>primitive.hpp. </p> <p> I'm not sure this is the right thing to do, and I don't understand why the constructor didn't have any body. Is there a default behavior for that kind of constructor ? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5106 Trac 1.4.3 Robert Ramey Sun, 23 Jan 2011 02:34:52 GMT <link>https://svn.boost.org/trac10/ticket/5106#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5106#comment:1</guid> <description> <p> Does making the following change in your test address the problem? </p> <pre class="wiki"> std::ofstream ofs( "./test.dat", ios::binary ); // add ios::binary ::boost::archive::binary_oarchive oa( ofs ); </pre><p> Note you fix in the header would override the definition in the library. This could cause a number of unanticipated side effects. You might check the definition in the library to see how it compares to yours. Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Sun, 23 Jan 2011 03:23:33 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5106#comment:2 https://svn.boost.org/trac10/ticket/5106#comment:2 <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">invalid</span> </li> </ul> Ticket