From -2733939218450673190
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,768d66e0db4648d6
X-Google-Attributes: gidf78e5,public
From: clamage@Eng.Sun.COM (Steve Clamage)
Subject: Re: new and delete
Date: 1995/09/13
Message-ID: <MATT.95Sep13110057@physics2.Berkeley.EDU>#1/1
X-Deja-AN: 110067003
approved: matt@physics2.Berkeley.EDU (Matt Austern)
references: <v02120d01ac7b940e834a@[164.76.64.3]>
organization: Sun Microsystems Inc., Mountain View, CA
newsgroups: comp.std.c++


chopps@water.emich.edu (Christian E. Hopps) writes:

>I have recently been working with a compiler vendor to fix some bugs regarding
>exceptions thrown during construction of "new" allocated objects.

>I have become totally confused as to the appropriate behavior when
>dealing with new-placement expressions.  Most of the confusion
>stems from a lack of clarity in the WP (this could just be me though.)

I think the WP is reasonably clear, but the subject is complicated.

Operator new must have a first argument of type size_t, and operator
delete must have a first argument of type void*. If the remaining
arguments match, the placement new and placement delete match.
(Except for the case noted below.)

The complication is that a class may have a member function
	void operator delete(void*, size_t); // #2

If that class ALSO has a member function
	void operator delete(void*);         // #1
then #2 is a placement-delete.

If that class does NOT also have a member #1, then #2 is not a
placement delete, but is an ordinary delete. (The old rule was
that a class could not have both, since delete could not be
overloaded. Now it can be overloaded.)

The only time this causes confusion is when
- you have a placement-new member function
	void* operator new(size_t, size_t)
- AND you have a member function
	void operator delete(void*, size_t)
- AND you do NOT have a member function
	void operator delete(void*)

In that one case, the operator delete looks like it matches the placement
new, but it doesn't; there is no match. In all other cases, the
argument test alone determines the match.

I haven't found any contradictory statements about this in the WP,
including what you referenced in the original article. The WP does
not mention all the possibilities in each place where it talks
about deallocation, so perhaps that is confusing. But if you do
find wording that seems contradictory or is in particular confusing
(as opposed to the subject being confusing), please let me know,
or post it here.
--
Steve Clamage, stephen.clamage@eng.sun.com

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]



