
Markus Schöpflin wrote:
Daniel Frey wrote:
Markus Schöpflin wrote:
boost.test currently contains an assortment of new operators which IMO are not conforming to the C++ std.
The implementation basically looks like this:
p = std::malloc(n); if (!p) throw std::bad_alloc();
This ignores the fact the std::malloc() is allowed to return either 0 or some unique pointer on zero sized requests, whereas a C++ allocation function _must_ return a unique pointer for each zero sized request.
I think it is guaranteed that a C++ allocation request (operator new) is never asked to allocate 0 bytes, thus the problem doesn't exist.
I'm sorry to insist, but what makes you think this might be the case? I have never ever heard of such a guarantee, but this of course doesn't mean much. Could you please point me to some reference for this?
I think operator new is intended to be called by new T. As zero sized types don't exist, operator new will never be called with n==0. But there's nothing which prevents you from calling operator new directly, so maybe it's even possible for operator new. What do the experts say? Was this intended or is it a defect report? Or am I missing something? (Note: I'm not talking about operator new[], which can be asked to allocate an array of zero objects as per 5.3.4/7) Regards, Daniel