public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* FW: A possible make_shared bug
       [not found] <SG2PR01MB2128C5DBEFC8781995E260D0FB950@SG2PR01MB2128.apcprd01.prod.exchangelabs.com>
@ 2019-10-09  8:51 ` Ming Cheng
  2019-10-09  9:33   ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Ming Cheng @ 2019-10-09  8:51 UTC (permalink / raw)
  To: libstdc++



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: gcc@gcc.gnu.org <gcc@gcc.gnu.org>
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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: FW: A possible make_shared bug
  2019-10-09  8:51 ` FW: A possible make_shared bug Ming Cheng
@ 2019-10-09  9:33   ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2019-10-09  9:33 UTC (permalink / raw)
  To: Ming Cheng; +Cc: libstdc++

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-09  9:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <SG2PR01MB2128C5DBEFC8781995E260D0FB950@SG2PR01MB2128.apcprd01.prod.exchangelabs.com>
2019-10-09  8:51 ` FW: A possible make_shared bug Ming Cheng
2019-10-09  9:33   ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).