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-06-07 17:50:29
#3080: dynamic_cast returns 0 on polymorphic serialization with weak_ptr
----------------------------------------------------+-----------------------
Reporter: Takatoshi Kondo <kondo_at_[hidden]> | Owner: ramey
Type: Bugs | Status: reopened
Milestone: Boost 1.40.0 | Component: serialization
Version: Boost 1.39.0 | Severity: Problem
Resolution: | Keywords:
----------------------------------------------------+-----------------------
Comment(by ramey):
I've been working on this problem and have found no way to fix it in a
definitive manner. A definitive fix would require enhancements in the
shared_ptr public
interface which I don't expect to occur.
The problem can be addressed in the test case:
{{{
struct Sub:public Base1, public Base2 {
int m_x;
boost::weak_ptr<Sub> m_wp; //fails
//boost::weak_ptr<Base2> m_wp; //OK
Sub(){}
Sub(int x) :
Base1(x),
Base2(x),
m_x(x)
{}
}}}
By using only one type of pointer to serialize the same object.
This problem only occurs when using shared pointer and it's friends.
I've updated the code to trap the condition and throw an exception
when it is discovered.
I've looked at your patch. First, I'm very impressed that you've
clearly understood how share_ptr_helper works and what it does. And
this is without any explanation and documentation!!!.
At first I was inclined to dismiss it as I had spent a lot of time
only to conclude that it wasn't fixable. Looking carefully at your
code - which looks very similar to my own attempts, now I'm thinking
you might be right. So I'm still looking at it. The problem for
me is that the shared_ptr operations in the public interface
are not all that transparent to me.
As for testing, I would expect that a much simpler test could be made.
{{{
class Base {
...
};
class Derived : public Base {
...
}
smart_ptr dptr = new Derived;
smart_ptr bptr = dptr;
// now there is only one object with pointers of different types
...
ar >> dptr;
ar >> bptr; // creates problem.
// dptr and bptr point to the same object
}}}
Anyway, I'm going to study your patch in more detail.
Robert Ramey.
PS - unfortunately, I had alread conclude that this was not fixable
and had updated the manual and exception list accordingly.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3080#comment:11> 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