Boost logo

Boost :

From: Loïc Joly (loic.joly_at_[hidden])
Date: 2006-01-30 05:32:59


Hello,

I have a class hierarchy that looks like this :

class A {/**/}; // Polymorphic
class B1 : virtual public A {/**/};
class B2 : virtual public A {/**/};
class C : public B1, public B2 {/**/};
class D : public C {/**/};

In C, I define the serialize function like this :

template <class Archive>
void C::serialize(Archive &ar, const unsigned int version)
{
   BOOST_SERIALIZATION_BASE_OBJECT_NVP(B1);
   BOOST_SERIALIZATION_BASE_OBJECT_NVP(B2);
   // serialize fields specific to C
}

When I try to serialize an object of type C, it works just fine.
However, when I try to serialize an object of class D, it fails. I have
not yet tried to reproduce this problem in fully a toy example, but I'm
going to do so ASAP.

I'm using VC++8.0.

When I try to debug the system, here is the information I get :

At one time, I'm in
save_pointer_type<xml_oarchive, A*> polymorphic::save
in line
vp = serialization::void_downcast(*true_type, *this_type, &t);

At that place, when I inspect t, all is fine (especially the vfprt).
Then I go in this void_downcast, where I can't inspect data, since the
pointer has been cast to a void type. Next time I gets back some type
info, i when calling :

void_downcast(
     const extended_type_info & derived_type, // D
     const extended_type_info & base_type, // A
     const void * const t,
     bool top)

In this function, I get an iterator at some point
void_cast_detail::void_caster_registry::const_iterator it;

That has the following content: Derived == D, Base == C.

Then, it calls void_caster_primitive::downcast with those informations,
where it calls
boost::smart_cast<const Derived *, const Base *>(
             static_cast<const Base *>(t)
// Derived == D, Base == C

However, in this function, declared that way:
template<class T, class U>
T smart_cast(U u);

If I try to look at the content of u, it seems totally broken. For
instance, the vfptr contains values such as
0xcdcdcdcd
0x00000000
...

 From my (limited) understanding of C++, casting from A* to void* and
back to C* is not supposed to work, but I'd like some confirmation.

Does someone have any idea about this problem, and if there is a
workaround ?

Best regards,

-- 
Loïc

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk