Re: [Boost-bugs] [Boost C++ Libraries] #2481: make_shared and allocate_shared friendship

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2481: make_shared and allocate_shared friendship
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-02-04 13:16:21

#2481: make_shared and allocate_shared friendship
  Reporter: Michael Marcin <mike.marcin_at_[hidden]> | Owner: pdimov
      Type: Feature Requests | Status: new
 Milestone: Boost 1.38.0 | Component: smart_ptr
   Version: Boost 1.36.0 | Severity: Problem
Resolution: | Keywords:
Changes (by Jonathan Wakely <jwakely.boost_at_[hidden]>):

 * cc: jwakely.boost_at_[hidden] (added)


 Right, you don't even need the make_shared_access extension to open that
 hole, the design is compromised if you declare make_shared or
 allocate_shared as a friend.

 class MustUseFactory {
   MustUseFactory() { }
   static shared_ptr<MustUseFactory> create();
 You can still use make_shared by using aliasing:
 shared_ptr<MustUseFactory> MustUseFactory::create()
     typedef aligned_storage<sizeof(MustUseFactory)> Storage;
     shared_ptr<Storage> storage = make_shared<Storage>();
     MustUseFactory* p = new (storage->address()) MustUseFactory();
     return shared_ptr<MustUseFactory>(storage, p);

 This doesn't work with enable_shared_from_this, I leave that as an
 exercise for the reader ;-)

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC