text: Q:
  
  Stop heap allocation via make_shared
  
  I want to force my object to be on the stack to enforce very strict semantics and address some lifetime concerns.  I've read a couple articles on how to do this, and arrived at making operator new private (or deleted).  This seems to work as expected when new is used directly, but make_shared compiles fine.
  #include <boost/smart_ptr.hpp>
  
  class A
  {
  private:
     void *operator new( size_t );
     void operator delete( void* );
     void *operator new[]( size_t );
     void operator delete[]( void* );
  };
  
  int main()
  {
  //  A* a = new A;      // Correctly produces compile error
      boost::shared_ptr<A> a2 = boost::make_shared<A>();
  }
  
  Using new A directly gives me this error as expected:
  error: ‘static void* A::operator new(size_t)’ is private
  
  I am guessing that make_shared is working because it is using the placement new operator, but I couldn't find any articles that discussed how to prohibit this.  The best solution I've come up with is to explicitly delete a template specialization for make_shared
  namespace boost
  {
      template<>
      shared_ptr<A> make_shared<A>() = delete;
  };
  
  This is obviously very specific to boost::make_shared though.  Is this really the best way?
  
  A:
  
  Placement forms of new are pretty easy to handle -- they just come with extra arguments.  For example, the simple placement form is
  void* operator new(std::size_t, void*);
  
  Note that 18.6.1.3 prohibits redefining these at global scope; however there should be no problem with redefining (or deleting/making inaccessible) them for your particular type.
  Unfortunately, make_shared uses scoped ::new  (pv)  T(std::forward<Args>(args)...).  And as I mentioned, you aren't allowed to mess with the global placement new.  So you can't prevent it at compile-time, and any runtime trap would be a hack (checking the this pointer to see whether it's in-bounds of the stack).
  
  