|
Boost : |
Subject: Re: [boost] deleting smart pointer
From: pavel (paul.cpprules_at_[hidden])
Date: 2011-03-19 06:16:45
Steven wrote on Saturday, March 19, 2011 at 1:31:51:
>> 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.
i see your point but you don't want to see mine
> [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."
it looks like you are citing the old std (or i have a corrupted copy)
here is the full citation of 5.3.5.2 of ISO/IEC 14882:2003(E) which,
i guess, you are referring to:
"If the operand has a class type, the operand is converted to a
pointer type by calling the above-mentioned conversion function, and
the converted operand is used in place of the original operand for the
remainder of this section. In either alternative, if the value of the
operand of delete is the null pointer the operation has no effect. In
the first alternative (delete object), the value of the operand of
delete shall be a pointer to a non-array object or a pointer to a
sub-object (1.8) representing a base class of such an object (clause
10). If not, the behavior is undefined. In the second alternative
(delete array), the value of the operand of delete shall be the
pointer value which resulted from a previous array new-expression.72)
If not, the behavior is undefined. [Note: this means that the syntax
of the delete-expression must match the type of the object allocated
by new, not the syntax of the new-expression. ] [Note: a pointer to a
const type can be the operand of a delete-expression; it is not
necessary to cast away the constness (5.2.11) of the pointer
expression before it is used as the operand of the
delete-expression.]"
feel free to prove me wrong
-- Pavel P.S. if you notice a grammar mistake or weird phrasing in my message please point it out
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk