Topic: operator delete[] and NULL


Author: steve@taumet.com (Steve Clamage)
Date: Sat, 12 Sep 1992 17:28:13 GMT
Raw View
matt@centerline.com (Matt Landau) writes:

|Speaking of operator delete[], is the effect of calling delete[] on NULL
|well-defined?  The ARM says plainly that "delete NULL" is legal, and a
|no-op, but I couldn't find anything explicit about "delete[] NULL", nor
|could I find any implication that operator delete and operator delete[]
|must behave the same way.
|The reason I ask is that, with USL cfront 2.1.12, I have found code that
|crashes intermittantly when asked to delete[] NULL.  I'm wondering if the
|code is correct and cfront is buggy, or vice versa.

The ARM says on p 63:
 "Deleting a pointer with the value zero, however,
 is guaranteed to be harmless."
This sentence immediate follows the syntax production
 deallocation-expression:
  delete cast-expression
  delete [ ] cast-expression
It doesn't restrict the guarantee to single-object deletion.

If your system doesn't allow
 T *p = 0;
 delete [] p;
then that is a bug.
--

Steve Clamage, TauMetric Corp, steve@taumet.com
Vice Chair, ANSI C++ Committee, X3J16




Author: matt@centerline.com (Matt Landau)
Date: 11 Sep 1992 18:30:55 GMT
Raw View
Speaking of operator delete[], is the effect of calling delete[] on NULL
well-defined?  The ARM says plainly that "delete NULL" is legal, and a
no-op, but I couldn't find anything explicit about "delete[] NULL", nor
could I find any implication that operator delete and operator delete[]
must behave the same way.

The reason I ask is that, with USL cfront 2.1.12, I have found code that
crashes intermittantly when asked to delete[] NULL.  I'm wondering if the
code is correct and cfront is buggy, or vice versa.
--
 Matt Landau   Waiting for a flash of enlightenment
 matt@centerline.com     in all this blood and thunder