https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99845

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Keith Halligan from comment #0)
> class MemAlloc {
>   public:
>     MemAlloc() {}
>     void* operator new[](size_t sz, const std::nothrow_t& nt) {
>         return ::operator new(sz, nt);
>     }

Why is this function written as an overloaded operator new?

You never use it for new-expressions like `new MemAlloc[n]` so why isn't it
just a normal named member function that allocates memory?

It isn't the cause of the bug, but it is confusing to have this extra operator
new[] involved that is a red herring.

It should probably be something like:

struct MemAlloc {
    static void* alloc(size_t sz) {
        return ::operator new(sz, std::nothrow);
    }
};

and then just call it as a normal static member function:

    void* operator new[](size_t sz, const std::nothrow_t&) {
        return MemAlloc::alloc(sz);
    }

Reply via email to