Opened 14 years ago

Closed 13 years ago

#2508 closed Bugs (fixed)

Serialization emits lots of warnings for MSVC7.1 (non-polymorphic / shared_ptr)

Reported by: Chard Owned by: Robert Ramey
Milestone: Boost 1.38.0 Component: serialization
Version: Boost 1.36.0 Severity: Problem
Keywords: non-polymorphic shared_ptr warnings MSVC 7.1 Cc:

Description

The serialization code emits many warnings if a non-polymorphic type is serialized via shared_ptr.

The following code demonstrates the issue:

#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <fstream>

struct X
{
    template <typename T>
    void serialize(T &ar, const unsigned int version)
    {}
};
typedef boost::shared_ptr<X> X_P;

void
test_ser()
{
    X_P x_p;

    std::ifstream ifstr("test.txt");
    boost::archive::text_iarchive ar(ifstr);
    ar & x_p;
}

Adding a virtual destructor to X causes the warnings to disappear, i.e. the serialization code wants the types to be polymorphic.

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.

Attachments (3)

test_static_warning.cpp-4.1.3-20080623pre-ubuntu.txt (9.0 KB ) - added by PhilR 13 years ago.
Output of g++-4.1 on ubuntu 9.04
test_static_warning.cpp-4.2.4-ubuntu.txt (9.0 KB ) - added by PhilR 13 years ago.
Output of g++-4.2 on ubuntu 9.04
test_static_warning.cpp-4.3.3-ubuntu.txt (10.3 KB ) - added by PhilR 13 years ago.
Output of g++-4.3 on ubuntu 9.04

Download all attachments as: .zip

Change History (13)

comment:1 by Marshall Clow, 14 years ago

Component: Noneserialization
Owner: set to Robert Ramey

comment:2 by Robert Ramey, 14 years ago

Status: newassigned

comment:3 by Chard, 13 years ago

In class: extended_type_info_typeid

Function:

    const extended_type_info * 
    get_derived_extended_type_info(const T & 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<T>::value); 
        return 
            detail::extended_type_info_typeid_0::get_extended_type_info( 
                typeid(t) 
            ); 
    }

The 'warning' that the class should be polymorphic is incorrect, as illustrated by this issue.

The reason this issue has not shown itself to gcc users is that the gcc static warning macro does not appear to work.

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…

In this case, MSVC71 is doing the 'right thing'.

comment:4 by Robert Ramey, 13 years ago

what does test_static_warning show with your gcc system? same for you vc 7.1 system.

Robert Ramey

in reply to:  4 ; comment:5 by Chard, 13 years ago

Replying to ramey:

what does test_static_warning show with your gcc system? same for you vc 7.1 system.

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<A>()" variants that did not warn - which seem to align with the check (above) in the serialization code.

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.

Regards...

in reply to:  5 comment:6 by PhilR, 13 years ago

Replying to Chard:

Replying to ramey:

what does test_static_warning show with your gcc system? same for you vc 7.1 system.

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<A>()" variants that did not warn - which seem to align with the check (above) in the serialization code.

(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<A>() code. VC 7.1 does.

Phil

comment:7 by Robert Ramey, 13 years ago

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.

I will be tweaking shared_ptr_helper to eliminate the spurious warning.

Robert Ramey

by PhilR, 13 years ago

Output of g++-4.1 on ubuntu 9.04

by PhilR, 13 years ago

Output of g++-4.2 on ubuntu 9.04

by PhilR, 13 years ago

Output of g++-4.3 on ubuntu 9.04

comment:8 by PhilR, 13 years ago

I've attached the output of the 3 versions of g++ installed on Ubuntu 9.04. Each one was generated by the command line:

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.

Let me know if there is anything else I can do that might pin this down for you,

Is it worth raising this as a separate ticket? (Does trac allow you to clone a ticket - that might be easier?)

Phil

comment:9 by Robert Ramey, 13 years ago

I've fixed the original issue in the trunk.

I re-ran test_warning.cpp - dammit if I don't see only 8 warnings. I suspect I was wrong before.

As it is now - I don't know how to fix this. Any suggestions welcome.

Robert Ramey

comment:10 by Robert Ramey, 13 years ago

Resolution: fixed
Status: assignedclosed

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.

Note: See TracTickets for help on using tickets.