FW: A possible make_shared bug

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

FW: A possible make_shared bug

chengm204


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

________________________________
From: Ming Cheng
Sent: Wednesday, October 9, 2019 3:08:50 PM
To: [hidden email] <[hidden email]>
Subject: A possible make_shared bug

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

Reply | Threaded
Open this post in threaded view
|

Re: FW: A possible make_shared bug

Jonathan Wakely-4
Please read the rest of my reply, as I already answered your question:
https://gcc.gnu.org/ml/gcc/2019-10/msg00075.html