Re: [Boost-bugs] [Boost C++ Libraries] #3080: dynamic_cast returns 0 on polymorphic serialization with weak_ptr

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #3080: dynamic_cast returns 0 on polymorphic serialization with weak_ptr
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-05-30 00:30:17


#3080: dynamic_cast returns 0 on polymorphic serialization with weak_ptr
----------------------------------------------------+-----------------------
  Reporter: Takatoshi Kondo <kondo_at_[hidden]> | Owner: ramey
      Type: Bugs | Status: new
 Milestone: Boost 1.40.0 | Component: serialization
   Version: Boost 1.39.0 | Severity: Problem
Resolution: | Keywords:
----------------------------------------------------+-----------------------

Comment(by Takatoshi Kondo <kondo_at_[hidden]>):

 I analyzed this problem.
 And, I finally noticed.

 Now, I have understood data member m_pointers in the shared_ptr_helper
 class keep information by the type shared_ptr<void> to achieve the
 restoration shared.

 The behavior of wps.c (Attached file) is same as the following simple
 sample.

 {{{
 #!cpp
 class Left {
 public:
         virtual ~Left() {}
 };
 class Right {
 public:
         virtual ~Right() {}
 };

 class Bottom:public Left, public Right {
 public:
         virtual ~Bottom() {}
 };

 int main() {
         Bottom b;
         void *pv = &b;
         Right *pr2 = static_cast<Right *>(pv);
         assert(dynamic_cast<Bottom *>(pr2)); // Fail
 }
 }}}

 The meaning of static_cast in this sample is same as the following code.
 https://svn.boost.org/trac/boost/browser/tags/release/Boost_1_39_0/boost/archive/shared_ptr_helper.hpp#L132

 In deserializing weak_ptr, it is inserted to m_pointers as
 shared_ptr<void>.
 https://svn.boost.org/trac/boost/browser/tags/release/Boost_1_39_0/boost/archive/shared_ptr_helper.hpp#L129

 Afterwards, when deserializing the shared_ptr, the following code is
 executed.
 https://svn.boost.org/trac/boost/browser/tags/release/Boost_1_39_0/boost/archive/shared_ptr_helper.hpp#L132

 Then, the problem occurs because the type of shared_ptr is 'Right' the
 second base class of 'Bottom'.

 -----
 I checked the document again.

 I had overlooked the following part of the document.

 http://www.boost.org/doc/libs/1_39_0/libs/serialization/doc/new_case_studies.html#archivehelper

 I'm not sure this problem is same as the current archive helper
 limitation.
 However, if it is exactly correct, this ticket should not be a bug but
 should be a feature requests.

 Could you give me your feedback?

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3080#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:00 UTC