Boost logo

Boost Users :

Subject: Re: [Boost-users] 1.39 serialisation: buggy warning message for shared_ptr
From: Avi Bahra (avibahra_at_[hidden])
Date: 2010-02-25 06:10:45


Robert Ramey wrote
>> The only reason to export a type is if one needs to
>> serialize it through a base class pointer. So, to me
>> the best way to suppress the warning would be
>> to not export the type.

The warning message appears even if you don't export
the type: Here is a simple test case
 //==================================
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/shared_ptr.hpp> // no need to include
shared_ptr
#include <boost/serialization/export.hpp>

class Concrete {
public:
   Concrete(const std::string& name ) : name_(name) {}
   Concrete() {}
private:
    std::string name_;
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive& ar,const unsigned int){
        ar & name_;
    }
};

class Base {
public:
   Base(const std::string& name ) : name_(name) {}
   Base() {}
   virtual ~Base(){}
private:
    std::string name_;
    *std::vector<boost::shared_ptr<Concrete> > vec_*;

    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int) {
        ar & name_;
        ar & vec_;
     }
};

class Derived : public Base {
public:
   Derived(const std::string& name ) : Base(name) {}
   Derived() {}
private:
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int) {
        ar & boost::serialization::base_object<Base>(*this);
    }
};

BOOST_CLASS_EXPORT(Derived);
 //==================================

Notice that I have not exported Concrete, but the
serialisation will spit out a warning message, about
class Concrete.

... boost_1_39_0/boost/serialization/extended_type_info_typeid.hpp", line
88:
warning #2414-D: delete of pointer to incomplete class
          BOOST_STATIC_WARNING(boost::is_polymorphic<T>::value);
          ^detected during:
            instantiation of "const boost::serialization::extended_type_info
*boost::serialization::extended_type_info_typeid<T>::get_derived_extended_type_info(const
T &) const [with T=Concrete]" at line 92 of
"/scratch/ma/emos/ma0/hpia64/boost/boost_1_39_0/boost/archive/shared_ptr_helper.hpp"

It looks like if we are serialising via a base ptr, and the
base class is serialising concrete data member via a shared ptr,
it has assumed that the type must be polymorphic. This does
not seem right to me ?

  Best regards,
Ta,
   Avi



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net