Topic: Question: Is "delete this;" legal?
Author: johnrp@well.sf.ca.us (John Panzer)
Date: Wed, 25 Nov 1992 09:50:52 GMT Raw View
Is it legal for an object to directly or indirectly delete itself
while within its own member function? I believe that it is, but
I cannot find a definitive statement. (Of course, all references
to member data would cause undefined behavior after the deletion,
but otherwise everything should be OK.)
John Panzer
johnrp@well.sf.ca.us
Author: adk@Warren.MENTORG.COM (Ajay Kamdar)
Date: 25 Nov 1992 11:15:01 -0500 Raw View
In article <By9nCs.C9u@well.sf.ca.us> johnrp@well.sf.ca.us (John Panzer) writes:
>
>Is it legal for an object to directly or indirectly delete itself
>while within its own member function? I believe that it is, but
>I cannot find a definitive statement. (Of course, all references
>to member data would cause undefined behavior after the deletion,
>but otherwise everything should be OK.)
>
There is a current discussion in comp.lang.c++ on exactly this topic.
The subject line of that discussion reads "Self Deletion". You might want
to take a look at it for more detailed information.
The reference manual in the ARM does not explicitly make self-deletion
legal or illegal. But in the commentary section 12.2c, on page 305, the
ARM gives an example which uses self-deletion and blesses the usage with
the comment "fine". This is sufficient for me to conclude that the intent
of the language is to permit self-deletion, and that it is legal to delete
"this".
It appears to be the consensus (between two people:-)) on comp.lang.c++ that
the draft standard should be amended to address this issue explicitly.
- Ajay
--
I speak for none but myself.
Ajay Kamdar Email : ajay_kamdar@mentorg.com
Mentor Graphics, IC Group (Warren, NJ) Phone : (908) 580-0102