This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: implicit use of placement new but not of placement delete


mark@codesourcery.com 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 :-)

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
        I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


This is about 5.3.4 [expr.new] 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  aschiem@math.uni-sb.de


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

class A{
public:
  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"
       <<flush;
  ::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"
       <<endl;
  ::operator delete(p);}
};


int main()
{try
  {new A;}
catch(...){;}
}
<<<<<end example
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]