
The situation is that with polymorphic base class, serialization library throws an exception. With non-polymorphic base class, the program succeeds. You are, probably, right that while x.cpp in my previous mail and test_exported.cpp throw the same exception, the cause may be different. I tried x.cpp (with polymorphic base class) with aCC instead of gcc and got: aCC runtime: Uncaught exception of type "boost::archive::archive_exception". At the same time, test_exported succeeds with aCC. I'll try serialization library at rrsd.com when I have a chance. In the meantime, do you have any idea why the program might be throwing exception with 1.35? Thanks, Boris Robert Ramey wrote:
One can't invoke any function of the derived class through a base class pointer unless the base class is polymorphic - that is has at least one virtual function.
Serialization is no different in this regard.
I would not expect the behavior of the program below to change between version.
The error message is the same as those failures in test_export but the cause isn't necessarily the same.
I would be curious of the version 1.36 serialization library at rrsd.com would pass tests with gcc 4.1 and higher.
Robert Ramey
Boris Gubenko wrote:
x.cpp below reproduces failures of test_exported* tests on several platforms using gcc 4.1 and higher. The tests fail with:
terminate called after throwing an instance of 'boost::archive::archive_exception' what(): unregistered void cast
When compiled with macro WORKS defined, i.e. when destructor of the base class is removed, reproducer succeeds. Does it give any clue?
Thanks, Boris
x.cpp ----- #include <fstream> #include <boost/archive/binary_oarchive.hpp>
struct polymorphic_base { template<class Archive> void serialize(Archive&, const unsigned int) {} #ifndef WORKS virtual ~polymorphic_base(){} #endif };
struct polymorphic_derived : polymorphic_base { template<class Archive> void serialize(Archive&, const unsigned int) {} };
int main() { std::ofstream os("x.x"); boost::archive::binary_oarchive oa(os); polymorphic_base *rb = new polymorphic_derived; oa << BOOST_SERIALIZATION_NVP(rb); }