From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-11-18 10:19:46
Robert Ramey wrote:
>>I'm just trying to find out why void_cast tests fail on gcc 3.3. Could you
>>answer two quick questions:
>>1. Why void_cast is needed in the first place. It's hard to debug it
>>without fully understanding the purpose.
> This is vaguely touched upon in the manual. I can be found in the last
> paragraph of
> the section "Pointers to Objects of Derived Classes".
I'd say that this section can confuse the reader. For a user, as opposed to
developer, it's not obvious why conversion between base and derived classes
should be done in some special way.
> For a better
> illustration of what it does look for void _downcast in oserializer.hpp
> where pointers of an abstract base type
> are converted to a pointer of the derived type. typeid gives it the most
> derived type at
> run time. Now how do we adjust the pointer from the base type to the
> correct derived type ?
IOW, you mean situation like
D* d = new D;
B* b = new B;
oa << b;
> void * derived_ptr = static_cast<?>(base_ptr)
> since ? isn't known until runtime we're stuck.
But... why do we need to cast void* to base into void* into derived? If I
understand correctly, in the case above you'll first call register_type,
which creates basic_serializer*. At this point, you still don't know the
most derived type. So, supposedly basic_serializer* actually points to
oserializer_pointer<T>. That instance does real saving of pointer, and the
first thing it does is:
T * t = static_cast<T *>(const_cast<void *>(x));
Why the first cast from base to derived is needed at all? I really can't
>>2. Are all BOOST_CHECK in 'test_void_cast.cpp' are supposed to be
>>completely independent from each other and work no matter how I rearrange
>>or comment out them?
> The only requirement for the test is that the registration of the
> pairs be left to the end. This emulates the case in the serialization
> system where by the serialization code comes before the base/derived pair
> regstration. void_cast_register is written so the table is built before
> main() is invoked.
Okay. I hope to find some time to look into it again.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk