Article View: comp.std.c++
Article #1960Re: new and delete
From: Fergus Henderson
Date: Wed, 13 Sep 1995 18:19
Date: Wed, 13 Sep 1995 18:19
66 lines
2960 bytes
2960 bytes
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.)
>
>First section 5.3.4(*) mentions an operator delete() that has almost the
>same type as the placement operator new() being used (all but the first
>argument matching.)
>
>Does this mean if I have e.g. void* operator new(size_t, void*)
>I can have an operator delete(void*, void*)?
Yes.
>Given the grammar
>for actually using "delete" there is no way to call this operator
>delete. (other than throwing an exception from a constructor :)
You can call such an operator delete using an ordinary function call,
e.g.
operator delete(p, q);
But there is no special "placement delete" syntax, so even though
you can write
q = new (p) T;
you can't write
delete (p) q;
The reason for this rather inconsistent state of affairs is that
various nasty parsing ambiguities would result if that syntax were
allowed.
>Well 5.3.4(*) references 3.7.3.2(**) which says that for global
>operator delete only one type is valid (void operator delete(void*))
>but for class members one can define two, namely:
>
> void operator delete(void*, size_t);
> void operator delete(void*);
3.7.3.2 is wrong, or at least misleading.
You are allowed to define operator delete functions with any
number of arguments.
>exactly what is supposed to occur when an object constructed from a
>placement-new throws while constructing?
I think the WP is reasonably clear on this: if there is a matching
operator delete function, it is called, otherwise nothing happens.
--
Fergus Henderson | #define x t=a[i],a[i]=a[m],a[m]=t/* use -O */
| char a[]=" 12345678";main(m,i,j,t){for(i=m;i<
fjh@cs.mu.oz.au | 9;x,i++)for(x,j=m;--j?(t=a[m-j]-a[m])-j&&t+j:
http://www.cs.mu.oz.au/~fjh | main(m+1)*0;);m-9||puts(a+1);} /* 8 queens */
[ 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. ]
Technical Details
Message-ID:
<9525704.3898@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<v02120d01ac7b940e834a@[164.76.64.3]>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: fjh@mundil.cs.mu.OZ.AU (Fergus Henderson) Newsgroups: comp.std.c++ Subject: Re: new and delete Date: 13 Sep 1995 18:19:34 GMT Organization: Computer Science, University of Melbourne, Australia Sender: news@cs.mu.OZ.AU (CS-Usenet) Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <9525704.3898@mulga.cs.mu.OZ.AU> References: <v02120d01ac7b940e834a@[164.76.64.3]> NNTP-Posting-Host: taumet.eng.sun.com Originator: clamage@taumet