Boost logo

Boost :

From: AlisdairM (AlisdairM_at_[hidden])
Date: 2001-10-18 02:19:44


Is the following also a bug?

#include <boost/smart_ptr.hpp>

class foo
{
public:
  foo( void ) {}
  ~foo( void ) { /* do something */ }
};

int main()
{
  foo x = 5;
  boost::shared_ptr<fo> px( &x );
}

This strikes me as an error in user code, as something other than the
scoped_ptr is responsible for the lifetime of the passed pointer.

The original example is the same problem, although better disguised.

AlisdairM

-----Original Message-----
From: Darin Adler [mailto:darin_at_[hidden]]
Sent: 18 October 2001 07:18
To: Boost
Subject: Re: [boost] shared_ptr bug?

on 10/17/01 11:07 PM, Fisher; Damien Kaine at dfisher_at_[hidden]
wrote:

> On Wed, 17 Oct 2001, Greg Colvin wrote:
>
>> class foo {
>> public:
>> foo(): m_self(this) { std::cout << "foo constructor\n"; }
>> ~foo() { std::cout << "foo destructor\n"; }
>> void suicide() { m_self.reset(0); }
>> private:
>> boost::shared_ptr<foo> m_self;
>> };
>
> Is m_self(this) legal? You are passing in a pointer to an object which
> has not yet been fully constructed. I am too sure whether that is
> appropriate or not, even though boost::shared_ptr doesn't really "use" the
> pointer.

I'm pretty sure it's legal, but it's beside the point for this example
anyway, since changing the constructor to this leaves us with the same
issue:

    foo() { m_self.reset(this); std::cout << "foo constructor\n"; }

    -- Darin

Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


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