------- Comment #6 from fang at csl dot cornell dot edu 2007-03-08 22:58 ------- Subject: Re: Overloaded operator delete[] doesn't get called
This following test case is 'interesting': ---------------->8 snip 8<--------------------- #include <iostream> using std::cout; class one_array_only { private: static one_array_only pool[256]; public: static void * operator new[] (std::size_t size) throw() { cout << "class new[] operator\n"; #if WTF return pool; #else return NULL; #endif } static void operator delete[] (void *p) throw() { cout << "class delete[] operator\n"; } }; one_array_only one_array_only::pool[256]; int main(int argc, char* argv[]) { one_array_only* p = new one_array_only[12]; delete [] p; return 0; } ---------------->8 snip 8<--------------------- Above, in operator new[], If WTF is false, returning NULL, I reproduce the same error (missing call to class operator delete []). If WTF is true (returning pool), the right operator delete [] is called. // output with WTF false class new[] operator // output with WTF true class new[] operator class delete[] operator Tested on: powerpc-apple-darwin8-g++-4.0.1 Why on earth would the definition inside operator new[] influence whether or not operator delete[] is called? Fang -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164