This is the mail archive of the gcc-bugs@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]

exception and matching operator delete


Dear GNUs,

I am not shure whether this is a bug report. I checked the new C++
standard about the question and could not find a definite answer. 
However, I am quite sure that my interpretation is the intended
behaviour. 
If during the evaluation of a new-expression the 
initialization of the new object causes an exception
then a matching operator delete is called 
(clause 5.3.4 17-19 of ISO/IEC 14882 C++ Standard).

In the example below a non-placement new-expression calls
operator new with 2 arguments (2nd of them is provided by a default
argument) and both egcs-1.0.3 and egcs-1.1.1 on Linux and HP-UX
chose the operator delete with one argument as the matching one.
I would say that the matching operator delete should be
determined by the declaration of the called operator new
disregarding default arguments. But I am not sure about
the definition of `placement allocation function' used to
describe the matching operator delete in the clause of the 
standard mentioned above.
-- Does 'placement allocation function' depend on the syntax of the
   new-expression that calls operator new
-- or on the declaration of the called operator new.

If you know a definite answer to this problem I would appreciate
a short note (aschiem@math.uni-sb.de). If you know someone 
'responsible' for clarifications you may as well forward this mail.

Thanks
Alexander Schiemann

>>>>>>>>>>> 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 is found disregarding\n"
       <<"   default arguments of operator new\n"
       <<flush;
  ::operator delete(p);}

  void A::operator delete(void* p)
  {cout<<"A::operator delete(void*)\n"
       <<"   matching operator delete depends on\n"
       <<"   default arguments of operator new\n"
       <<flush;
  ::operator delete(p);}
};


int main()
{try
  {new A;}
catch(...){;}
}
<<<<<end example




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