Topic: Defect Report: what shall do user dealloc func with NULL?


Author: "Ruslan Abdikeev" <ruslan@vr1.spb.ru>
Date: 01 Apr 02 09:20:34 GMT
Raw View
 [Moderator's note: this defect report has been
 forwarded to the C++ committee. -moderator.]

Hello,

Standard is clear on behaviour of default allocation/deallocation
functions.
However, it is surpisingly vague on requirements to the behaviour
of user-defined deallocation function and an interaction between
delete-expression and deallocation function.
This caused a heated argument on fido7.su.c-cpp newsgroup.


Resume:

It is not clear if user-supplied deallocation function is called from
delete-expr when the operand of delete-expr is the null
pointer (5.3.5, expr.delete).
If it is, standard does not specify what user-supplied
deallocation function shall do with
the null pointer operand (18.4.1, lib.new.delete).
Instead, Standard uses the term "has no effect", which meaning
is too vague in context given (5.3.5, expr.delete).


Description:

Consider statements

   char* p= 0; //result of failed non-throwing ::new char[]
   ::delete p;

Argument passed to delete-expression is valid - it is the result
of a call to the non-throwing version of ::new, which has been failed.
5.3.5/1 (expr.delete) explicitly prohibit us to pass 0
without having the ::new failure.

Standard does NOT specify whether user-defined deallocation function
should be called in this case, or not.

Specifically, standard says:

   "...if the value of the operand of delete is the null pointer the operation
   has no effect."  (5.3.5/2, expr.delete)

Standard doesn't specify term "has no effect".
It is not clear from this context, whether the called deallocation function
is required to have no effect, or delete-expression shall not call
the deallocation function.
Furthermore, in para 4 standard says on default deallocation function:

   "If the delete-expression calls the implementation deallocation
   function (3.7.3.2, basic.stc.dynamic.deallocation),
   if the operand of the delete expression is not
   the null pointer constant, ..." (5.3.5/4, expr.delete)

Why it is so specific on interaction of default deallocation function
and delete-expr?

If "has no effect" is a requirement to the deallocation function,
then it should be stated in 3.7.3.2 (basic.stc.dynamic.deallocation),
or in 18.4.1.1 (lib.new.delete.single) and 18.4.1.2 (lib.new.delete.array),
and it should be stated explicitly.

Furthermore, standard does NOT specify what actions shall
be performed by user-supplied deallocation function if NULL
is given:

   "Required behaviour: accept a value of ptr that is null or that was
   returned by an earlier call to the default operator new(std::size_t)
   or operator new(std::size_t, const std::nothrow_t&)."
   (18.4.1.1/12, lib.new.delete.single)

The same corresponds to ::delete[] case.


Expected solution:

1. Make it clear that delete-expr will not call deallocation function
if null pointer is given (in 5.3.5, expr.delete).

2. Specify what user deallocation function shall do when null is given
(either in 3.7.3.2, basic.stc.dynamic.deallocation, or
in 18.4.1.1, lib.new.delete.single, and 18.4.1.2, lib.new.delete.array).


Sincerely,
Ruslan Abdikeev
email: ruslan@vr1.spb.ru
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]




Author: "Ruslan Abdikeev" <ruslan@vr1.spb.ru>
Date: Mon, 1 Apr 2002 22:12:20 GMT
Raw View
"Ruslan Abdikeev" <ruslan@vr1.spb.ru> wrote in message news:a8979t$o3i$1@news.wplus.spb.ru...
> Consider statements
>
>    char* p= 0; //result of failed non-throwing ::new char[]
>    ::delete p;
>

My apologies, it should be read as

     ::delete[] p;

Just to remove an ambiguity,

Ruslan Abdikeev



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]