Thread overview
DMC 8.45 and new/delete
Sep 27, 2005
Wu Yongwei
Sep 28, 2005
Walter Bright
Re: DMC 8.45 and new/delete - test.cpp
Sep 28, 2005
Wu Yongwei
September 27, 2005
Hi, Walter,

While I believe DMC has improved much in standard conformance, it is always weak in new/delete.  I have not been to compile my memory leak detector <URL:http://wyw.dcweb.cn/leakage.htm> under DMC because of this.  Specifically it has the following problems:

1) Exception specification in operator new/delete results in an obscure message like:

test.cpp(4) : Error: 'operator new' previously declared as something else
It was declared as: void *C func(unsigned )
It is now declared: void *C func(unsigned )

Even "throw()" cannot be used:

test.cpp(9) : Error: 'operator del' previously declared as something else
It was declared as: void C func(void *)
It is now declared: void C func(void *)

(And 'operator del' does not look better than 'operator delete'.)

2) Placement deallocation functions cannot be declared or defined:

test.cpp(9) : Error: must be void operator delete(void * [,size_t]);

3) `operator new' still defaults to the nothrow mode.  (Hey, old code should use old compilers, or define their own global `operator new'.  Microsoft's `operator new' does not throw in MSVC 6.0, but it does in MSVC 7.1.)

4) Use of new(nothrow) gives a strange error:

no_ptr = new(nothrow) Obj;
^
test.cpp(15) : Error: no match for function '?2(unsigned ,const std::nothrow_t)'

I really, really hope you can improve on this.

Best regards,

Yongwei


September 28, 2005
All right, it's probably time to fix all that.


September 28, 2005
C:\TEMP>test

C:\TEMP>test 1
Object deleted
Exception

The "Object deleted" message shows a problem: `operator delete' should not be called in this case.  It is an old problem too.  This can really harm normal program that can throw in constructors.

Best regards,

Yongwei