Path: utzoo!attcan!uunet!wuarchive!usc!elroy.jpl.nasa.gov!ames!sgi!shinobu!odin!delrey.sgi.com!shap From: shap@delrey.sgi.com (Jonathan Shapiro) Newsgroups: comp.lang.c++ Subject: Change to delete is in order Message-ID: <5136@odin.SGI.COM> Date: 12 Mar 90 16:22:06 GMT Sender: news@odin.SGI.COM Reply-To: shap@delrey.sgi.com (Jonathan Shapiro) Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 29 I believe that a small change to the definition of the delete operator is worth considering. The change would have no effect on correct programs, but would help find incorrect programs in some circumstances. delete should be defined to zero the pointer it is handed after freeing the associated store. Reasons: 1. Unlike C, C++ does not guarantee that the object is live until the next call to new. 2. In the absence of setting the pointer to zero, accesses to data items that erroneously follow the delete cannot be caught even when the hardware traps page-zero references, and compilers have not yet arrived that understand about this. 3. If the code is correct, dead code elimination in the compiler can generally be relied on to eliminate the zero set, so the run-time cost should be nil. 4. I can't think of a correct code sequence it would break. Of course, compilers should be taught to understand about use after clobber, but that's a bit harder, and I don't see how this tweak to the language spec can hurt. Jonathan Shapiro Silicon Graphics, Inc.