Boost logo

Boost :

From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2008-04-09 14:16:10


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 09 April 2008 14:07 pm, Daniel Frey wrote:
> On Wed, 2008-04-09 at 13:47 -0400, Frank Mori Hess wrote:
> > On Wednesday 09 April 2008 11:13 am, Daniel Frey wrote:
> > > I have use cases which would be a lot easier to implement if
> > > shared_from_this() never throws. And - at least with the "old"
> > > implementation - I don't see any reason why this guarantee should not
> > > hold. Of course it's not a defect, but to me it seems desirable.
> >
> > It is technically possible to make it throw without violating the
> > functions documented requirements, if there are multiple owners. For
> > example, if pass the raw pointer to multiple shared_ptrs with null
> > deleters.
>
> Could you provide a small but complete code example, please? I fail to
> see how that case should be legal.

Here you go, this throws against the old library. It doesn't against the
trunk, due to a slight change in behavior, but could easily be modified to do
so.

- --
Frank
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFH/Qfu5vihyNWuA4URAgMaAKCpxwhzr7c4wIpxWjOTizCeWLGZaQCeI8jV
Ta0uHXG6PRTWMI224Z67WF4=
=DOZL
-----END PGP SIGNATURE-----

--Boundary-00=_ufQ/HvSpYB1HNa1
Content-Type: text/x-c++src; charset="iso-8859-1";
        name="shared_from_this_throw.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
        filename="shared_from_this_throw.cpp"

#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>

void null_deleter(const void*)
{}

class myclass: public boost::enable_shared_from_this<myclass>
{};

int main()
{
        myclass *myobj = new myclass;
        boost::shared_ptr<myclass> ptr(myobj);
        {
                boost::shared_ptr<myclass> ptr2(myobj, &null_deleter);
        }
        ptr->shared_from_this();
        return 0;
}

--Boundary-00=_ufQ/HvSpYB1HNa1--


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