2008/10/28 S. Tang <[EMAIL PROTECTED]>:
> Hello there,
>
> From what I understand, if one uses placement new with a parameter to 
> initialize a class, and if that class' constructor throws an exception, then 
> a matching delete operator is called to release the memory.
>
> This does not seem to work if the overloaded delete operator is a template 
> function.

I think you've found a bug. Here is a reduced test which should fail
to compile, but gcc accepts it:

#include <stddef.h>

template <class T> class undef;

struct MyClass
{
 MyClass() { throw 1; } // constructor throws exception
};

template<typename T> class Pool2 { };

template<typename T>
inline void *operator new(size_t size,Pool2<T>& pool)
{
 return new char[size];
}

template<typename T>
inline void operator delete(void *p,Pool2<T>& pool)
{
 undef<T> t;        // ERROR
 delete[] (char*)p;
}

int main (int argc, char * const argv[]) {
 Pool2<int> pool2;

 try {
   MyClass *myclass = new (pool2) MyClass(); // delete not called!
 } catch(...) { }

 return 0;
}

Reply via email to