Boost C++ Libraries: Ticket #2508: Serialization emits lots of warnings for MSVC7.1 (non-polymorphic / shared_ptr) https://svn.boost.org/trac10/ticket/2508 <p> The serialization code emits many warnings if a non-polymorphic type is serialized via shared_ptr. </p> <p> The following code demonstrates the issue: </p> <pre class="wiki">#include &lt;boost/archive/text_iarchive.hpp&gt; #include &lt;boost/serialization/serialization.hpp&gt; #include &lt;boost/serialization/shared_ptr.hpp&gt; #include &lt;fstream&gt; struct X { template &lt;typename T&gt; void serialize(T &amp;ar, const unsigned int version) {} }; typedef boost::shared_ptr&lt;X&gt; X_P; void test_ser() { X_P x_p; std::ifstream ifstr("test.txt"); boost::archive::text_iarchive ar(ifstr); ar &amp; x_p; } </pre><p> Adding a virtual destructor to <strong>X</strong> causes the warnings to disappear, i.e. the serialization code <em>wants</em> the types to be polymorphic. </p> <p> This appears to be an issue when building with MSVC (though only tested with 7.1) because gcc 4.3.2 does not emit the warnings. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2508 Trac 1.4.3 Marshall Clow Tue, 18 Nov 2008 00:54:43 GMT component changed; owner set https://svn.boost.org/trac10/ticket/2508#comment:1 https://svn.boost.org/trac10/ticket/2508#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Robert Ramey</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">serialization</span> </li> </ul> Ticket Robert Ramey Sun, 04 Jan 2009 17:28:05 GMT status changed https://svn.boost.org/trac10/ticket/2508#comment:2 https://svn.boost.org/trac10/ticket/2508#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Chard Thu, 30 Jul 2009 13:38:50 GMT <link>https://svn.boost.org/trac10/ticket/2508#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2508#comment:3</guid> <description> <p> In class: extended_type_info_typeid </p> <p> Function: </p> <pre class="wiki"> const extended_type_info * get_derived_extended_type_info(const T &amp; t) const { // note: this implementation - based on usage of typeid (rtti) // only does something if the class has at least one virtual function. BOOST_STATIC_WARNING(boost::is_polymorphic&lt;T&gt;::value); return detail::extended_type_info_typeid_0::get_extended_type_info( typeid(t) ); } </pre><p> The 'warning' that the class should be polymorphic is incorrect, as illustrated by this issue. </p> <p> The reason this issue has not shown itself to gcc users is that the gcc static warning macro does not appear to work. </p> <p> We've investigated the division-by-zero method (for gcc 3.3), and it appears that gcc doesn't bother stamping out the "struct STATIC_WARNINGxxxx". By declaring an actual instance of the STATIC_WARNINGxxxx struct and then calling the f() method on it, the warnings then start trailing out… </p> <p> In this case, MSVC71 is doing the 'right thing'. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Mon, 03 Aug 2009 22:39:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2508#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2508#comment:4</guid> <description> <p> what does test_static_warning show with your gcc system? same for you vc 7.1 system. </p> <p> Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Chard</dc:creator> <pubDate>Wed, 05 Aug 2009 21:54:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2508#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2508#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2508#comment:4" title="Comment 4">ramey</a>: </p> <blockquote class="citation"> <p> what does test_static_warning show with your gcc system? same for you vc 7.1 system. </p> </blockquote> <p> A colleague ran this test through his g++ 4.3.3 system, and it only reported eight warnings - not the required ten. </p> <p> I believe it was the "f&lt;A&gt;()" variants that did not warn - which seem to align with the check (above) in the serialization code. </p> <p> However, this is ultimately a side-issue (even though it may have disguised behaviour) and the main issue is that it looks like the serialization code for shared_ptr needs to check for polymorphism, and route accordingly. I see there are other places in the serialization code that do this with a bit of mpl::eval_if. </p> <p> Regards... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>PhilR</dc:creator> <pubDate>Fri, 07 Aug 2009 07:33:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2508#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2508#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2508#comment:5" title="Comment 5">Chard</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2508#comment:4" title="Comment 4">ramey</a>: </p> <blockquote class="citation"> <p> what does test_static_warning show with your gcc system? same for you vc 7.1 system. </p> </blockquote> <p> A colleague ran this test through his g++ 4.3.3 system, and it only reported eight warnings - not the required ten. I believe it was the "f&lt;A&gt;()" variants that did not warn - which seem to align with the check (above) in the serialization code. </p> </blockquote> <p> (I'm the "colleague".) I ran the test on g++ 4.3.3 and 3.3.x - both of these do not report static warnings on the f&lt;A&gt;() code. VC 7.1 does. </p> <p> Phil </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Sun, 23 Aug 2009 17:12:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2508#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2508#comment:7</guid> <description> <p> Hmmm - I ran test_static_warning on GCC 4.3.2 under cygwin and I get 10 warning messages. This looks OK to me. I'm not sure what to do now. </p> <p> I will be tweaking shared_ptr_helper to eliminate the spurious warning. </p> <p> Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <dc:creator>PhilR</dc:creator> <pubDate>Wed, 26 Aug 2009 18:24:29 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2508 https://svn.boost.org/trac10/ticket/2508 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_static_warning.cpp-4.1.3-20080623pre-ubuntu.txt</span> </li> </ul> <p> Output of g++-4.1 on ubuntu 9.04 </p> Ticket PhilR Wed, 26 Aug 2009 18:25:05 GMT attachment set https://svn.boost.org/trac10/ticket/2508 https://svn.boost.org/trac10/ticket/2508 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_static_warning.cpp-4.2.4-ubuntu.txt</span> </li> </ul> <p> Output of g++-4.2 on ubuntu 9.04 </p> Ticket PhilR Wed, 26 Aug 2009 18:25:31 GMT attachment set https://svn.boost.org/trac10/ticket/2508 https://svn.boost.org/trac10/ticket/2508 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_static_warning.cpp-4.3.3-ubuntu.txt</span> </li> </ul> <p> Output of g++-4.3 on ubuntu 9.04 </p> Ticket PhilR Wed, 26 Aug 2009 18:30:08 GMT <link>https://svn.boost.org/trac10/ticket/2508#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2508#comment:8</guid> <description> <p> I've attached the output of the 3 versions of g++ installed on Ubuntu 9.04. Each one was generated by the command line: </p> <p> g++-4.x -v -Wall -W -Wextra -H -I../../../ test_static_warning.cpp -c (for x = 1, 2, 3) inside the directory boost/libs/serialization/test. </p> <p> Let me know if there is anything else I can do that might pin this down for you, </p> <p> Is it worth raising this as a separate ticket? (Does trac allow you to clone a ticket - that might be easier?) </p> <p> Phil </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Wed, 26 Aug 2009 20:59:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2508#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2508#comment:9</guid> <description> <p> I've fixed the original issue in the trunk. </p> <p> I re-ran test_warning.cpp - dammit if I don't see only 8 warnings. I suspect I was wrong before. </p> <p> As it is now - I don't know how to fix this. Any suggestions welcome. </p> <p> Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Fri, 11 Sep 2009 18:09:16 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2508#comment:10 https://svn.boost.org/trac10/ticket/2508#comment:10 <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> Reimplemented BOOST_STATIC_WARNING to depend upon boost::mpl::print. I've tested it on MSVC 7.1 and gcc 4.3.2 and it seems to work fine - though the output is "cleaner" with gcc. I've checked it into the trunk to see how it works. </p> Ticket