Boost C++ Libraries: Ticket #1267: Assertion `new_cid == cid' failed in basic_iarchive https://svn.boost.org/trac10/ticket/1267 <p> This has previously been reported on <a class="ext-link" href="http://lists.boost.org/boost-users/2006/01/16604.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2006/01/16604.php</a> </p> <p> This bug seems to appear when a class containing a polymorphic object pointer is serialized with separate save/load methods and the BOOST_IS_ABSTRACT() macro is used on the polymorphic base. </p> <p> I've attached a simpler test case which is another modified version of test_exported.cpp based on Troy D. Straszheim's version in the above mailing list post. It fails on GCC 3.2.3 and 3.4.5 (Linux x86) with: </p> <pre class="wiki">../../../libs/serialization/src/basic_iarchive.cpp:466: const boost::archive::detail::basic_pointer_iserializer* boost::archive::detail::basic_iarchive_impl::load_pointer( boost::archive::detail::basic_iarchive&amp;, void*&amp;, const boost::archive::detail::basic_pointer_iserializer*, const boost::archive::detail::basic_pointer_iserializer*(*)(const boost::serialization::extended_type_info&amp;)): Assertion `new_cid == cid' failed. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1267 Trac 1.4.3 mbergin@… Fri, 14 Sep 2007 16:26:36 GMT <link>https://svn.boost.org/trac10/ticket/1267#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1267#comment:1</guid> <description> <p> I am having trouble attaching the test case; Trac is telling me it is spam. </p> </description> <category>Ticket</category> </item> <item> <author>mbergin@…</author> <pubDate>Fri, 14 Sep 2007 16:27:29 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/1267 https://svn.boost.org/trac10/ticket/1267 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_exported.cpp.gz</span> </li> </ul> Ticket mbergin@… Sun, 16 Sep 2007 17:27:53 GMT <link>https://svn.boost.org/trac10/ticket/1267#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1267#comment:2</guid> <description> <p> Also tested on VC8 and fails. The serialized output of the above test case is below. Are the class IDs being output in the wrong order? </p> <pre class="wiki">&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?&gt; &lt;!DOCTYPE boost_serialization&gt; &lt;boost_serialization signature="serialization::archive" version="4"&gt; &lt;c class_id="0" tracking_level="0" version="0"&gt; &lt;px class_id="2" class_name="polymorphic_derived" tracking_level="1" version="0" object_id="_0"&gt; &lt;polymorphic_base class_id="1" tracking_level="1" version="0" object_id="_1"&gt;&lt;/polymorphic_base&gt; &lt;/px&gt; &lt;/c&gt; &lt;/boost_serialization&gt; </pre> </description> <category>Ticket</category> </item> <item> <author>gwossum@…</author> <pubDate>Wed, 19 Sep 2007 19:32:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1267#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1267#comment:3</guid> <description> <p> I've encountered the same problem with g++ 3.2.3. With g++ 3.2.3, it occurs any time I try to serialize a thaw a derived class through an abstract base class pointer, whether or not separate save and load methods are used. Dropping the BOOST_CLASS_EXPORT() for the abstract base class does NOT fix the problem. Only making the base class non-abstract makes the problem go away, which isn't always an appealing option. </p> <p> As a curious note, I have a class heirarchy that involves an abstract base class A, an abstract subclass of A (B), and a several concrete subclasses of B. I encounter issues if A is abstract, but if I make A concrete but B is still abstract, I don't get any problems. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 22 Sep 2007 08:13:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1267#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1267#comment:4</guid> <description> <p> The short answer is: </p> <blockquote> <p> BOOST_IS_ABSTRACT(<strong>const</strong> polymorphic_base) </p> </blockquote> <p> Rake are hidden in basic_xml_oarchive::save_override(nvp&lt;T&gt;&amp;) method: </p> <pre class="wiki"> template&lt;class T&gt; void save_override( #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING const #endif ::boost::serialization::nvp&lt;T&gt; &amp; t, int ){ this-&gt;This()-&gt;save_start(t.name()); archive::save(* this-&gt;This(), t.const_value()); /// CONST!! this-&gt;This()-&gt;save_end(t.name()); } </pre><p> nvp&lt;T&gt;::const_value() method allways returns constant reference and it doesn't matter what type you have passed to nvp&lt;T&gt;'s ctor. </p> <pre class="wiki"> const T &amp; const_value() const { return *(this-&gt;second); } </pre><p> So, in save_pointer_type::register_type method() the serialization::is_abstract&lt;T&gt; check is always being applied not to the constant type. IMHO it is better to fix serialization::is_abstract, but as a temporary solution additional BOOST_IS_ABSTRACT directive for constant type can be used. </p> <p> P.S. I investigated this problem with boost-1.33.1 using GCC 3.4.5 (MinGW) and Intel 8.0 compiler. </p> </description> <category>Ticket</category> </item> <item> <author>gwossum@…</author> <pubDate>Mon, 24 Sep 2007 21:58:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1267#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1267#comment:5</guid> <description> <p> Tried the BOOST_CLASS_EXPORT(const <a class="missing wiki">PolymorphicBase</a>) with boost-1.33.1 and gcc 3.2.3. Got a static assertion at archive/detail/iserializer.hpp line 610. The comment around this suggests the assertion is due to gcc 3.2.3 not having correct function template ordering. Could this be part of the problem with gcc 3.2.3? </p> </description> <category>Ticket</category> </item> <item> <author>mbergin@…</author> <pubDate>Tue, 23 Oct 2007 12:15:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1267#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1267#comment:6</guid> <description> <p> This works for me on GCC3.2.3, but it's important to note you need to do both BOOST_IS_ABSTRACT(polymorphic_base) BOOST_IS_ABSTRACT(const polymorphic_base) for it to compile. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Fri, 30 Nov 2007 07:12:47 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/1267#comment:7 https://svn.boost.org/trac10/ticket/1267#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Robert Ramey Sat, 01 Dec 2007 00:10:31 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1267#comment:8 https://svn.boost.org/trac10/ticket/1267#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> resolved by folding T to const T in serialization/is_abstract </p> Ticket anonymous Wed, 23 Jan 2008 00:53:06 GMT <link>https://svn.boost.org/trac10/ticket/1267#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1267#comment:9</guid> <description> <p> I was curious as to what the fix was (as it isn't available in 1.34.1). For those interested: I've pinned it down to <a class="changeset" href="https://svn.boost.org/trac10/changeset/42254" title="Corrections to address TRAK tickets">r42254</a>. </p> </description> <category>Ticket</category> </item> </channel> </rss>