From -8693652553743554472
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,768d66e0db4648d6
X-Google-Attributes: gidf78e5,public
From: fjh@mundil.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: new and delete
Date: 1995/09/13
Message-ID: <9525704.3898@mulga.cs.mu.OZ.AU>#1/1
X-Deja-AN: 110067004
approved: clamage@eng.sun.com (comp.std.c++)
sender: news@cs.mu.OZ.AU (CS-Usenet)
references: <v02120d01ac7b940e834a@[164.76.64.3]>
organization: Computer Science, University of Melbourne, Australia
newsgroups: comp.std.c++
originator: clamage@taumet

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. ]




