|
Boost : |
Subject: Re: [boost] deleting smart pointer
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-03-18 18:31:51
AMDG
On 03/18/2011 01:54 PM, pavel wrote:
> Steven wrote on Friday, March 18, 2011 at 21:02:13:
>> Second, how is it horrible? Of course it is (almost) like
>> p.reset(). Assigning anything to a shared_ptr
>> decrements the reference count on the old value.
> rephrasing your words: how is 'delete p' a bad idea? it's obvious it
> is almost like 'p.reset()'
No it isn't. The difference is that assignment
is a basic operation for a smart_ptr, and it's
behaving in the normal way. It isn't a matter
of being "almost like" reset.
>> Except that the tricks you use to implement
>> it result in undefined behavior...
> i inspected the std and didn't find anything which may result in
> undefined behavior
>
> did i miss anything?
>
[expr.delete]
"...In the first alternative (delete object), the value of the operand
of delete may be a null pointer
value, a pointer to a non-array object created by a previous
new-expression, or a pointer to a subobject (1.8)
representing a base class of such an object (Clause 10). If not, the
behavior is undefined."
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk