implicit use of placement new but not of placement delete

Nathan Sidwell
Wed Jun 30 23:15:00 GMT 1999 wrote:
> Actually, I'd better read the standard over one more time before I
> approve this patch.  I'll let you know tomorrow, unless Jason beats me
> to it.
FYI, in case you've not seen this Alexander Schiemann submitted the attached
defect report to comp.std.c++ about this issue.

FWIW I can't tell what the standard wants here, but Alexander S's proposal
takes the principle of least surprise. If the standard does require us to call
the non-placement delete it'd be a good idea to warn somewhere :-)


Dr Nathan Sidwell :: Computer Science Department :: Bristol University
        I have seen the death of PhotoShop -- it is called GIMP

Subject : Defect Report: ambiguity 'matching deallocation function'
>From : Alexander Schiemann <aschiem at math dot uni-sb dot de>
Date : 08 Jun 99 14:35:46 GMT
Approved : Valentin Bonnard <>
Newsgroups : comp.std.c++
Organization : Universitaet des Saarlandes  FB Mathematik
Xref : comp.std.c++:37201

This is about 5.3.4 [] paragraph 17-19 (p.80)

If an exception occurs during object initialization in a new-
expression then a 'matching deallocation function' (if unambiguous)
is called. Paragraph 19 defines the matching deallocation function
for placement allocation functions and non-placement ones. 

I did not find a definition of 'placement allocation function' that
solves the following ambiguity:
If one declares an allocation function with a 2nd parameter but
supplies a default argument then this function may be called from a
new-expression without placement argument. If we look for a matching
deallocation function should we look for one with a placement argument
or not? I.e. does the term 'placement allocation function' depend 
1. on the declaration of the function (disregarding default arguments
   used in the call)
2. or on the syntax of the new-expression that calls the allocation
   function ?

My favorite answer is 1) but the egcs compiler (versions 1.0.3--1.1.2)
says 2).

Alexander Schiemann

>>>>>>>>>>> begin example
#include <iostream.h>

class A{
  {throw 5;}

  void* operator new(size_t size, double x=3.5)
  {cout<<"A::operator new(size_t,double)\n";
  return ::operator new(size);}

  void operator delete(void* p, double)
  {cout<<"A::operator delete(void*,double)\n"
       <<"   matching operator delete with placement argument\n"
       <<"   although no explicit placement argument in the\n"
       <<"   new-expression\n"
  ::operator delete(p);}

  void A::operator delete(void* p)
  {cout<<"A::operator delete(void*)\n"
       <<"   matching non-placement operator delete\n"
       <<"   for operator new called with default placement argument"
  ::operator delete(p);}

int main()
  {new A;}
<<<<<end example
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ:              ]

More information about the Gcc-patches mailing list