A possible make_shared bug

Ming Cheng chengm349@hotmail.com
Wed Oct 9 07:08:00 GMT 2019


Hi GCC developers:

Assume I have a class:

Class FOO
{
Public:
    void* operator new(size_t size);
    void* operator new(size_t size, const std::nothrow_t &) noexcept;
    void  operator delete(void *doomed,size_t size);
    void* operator new [](size_t size);
    void  operator delete [](void* object);
    static void NewMemPool();
    static void DeleteMemPool();
}

These operator new/delete will get a buffer from a mempool created by NewMemPool and return a buffer to the pool.
Now if I have stmt without first call NewMemPool() :

std::shared_ptr<FOO> p(new FOO());

the program will crash.

However if I just call this directly

auto& p = std::make_shared<FOO>();  // I did not call NewMemPool yet.
My program is happy.

Should std::make_shared call my class operator new also? What’s the concept behind std::make_shared?

Warm Regards.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10



More information about the Gcc mailing list