[cfe-dev] is delete on abstract with non-virtal ever safe?
Sebastian Redl
sebastian.redl at getdesigned.at
Sun Oct 6 02:44:54 PDT 2013
On Oct 5, 2013, at 19:21, emmanuel.attia wrote:
> I agree that the 5.3.5 rule is contradictory into what I do, but introduction
> of chap 5 states:
>
> "2. Operators can be overloaded, that is, given meaning when applied to
> expressions of class type (clause 9) or enumeration type (7.2). Uses of
> overloaded operators are transformed into function calls as described in
> 13.5. Overloaded operators obey the rules for syntax specified in clause 5,
> but the requirements of operand type, lvalue, and evaluation order are
> replaced by the rules for function call."
>
> So is 5.3.5 really a requirement of any delete operator or only of the
> default one ?
>
> For the default delete operator since the behavior is to free the memory it
> would make sense to require the destructor of the object to be callable by
> putting a virtual destructor in the base interface.
operator delete (like operator new) does not behave like other overloaded operators, because it doesn't replace the entire behavior of the delete operator. It just replaces the memory deallocation part. In particular, unlike all other operators, `delete foo` isn't equivalent to `operator delete(foo)`.
Sebastian
More information about the cfe-dev
mailing list