[PATCH] D30837: [libcxx] Support for shared_ptr<T()>

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 10 10:27:40 PST 2017


erik.pilkington created this revision.

This patch adds support for `shared_ptr<T()>` types, so that the following works:

  void Func();
  void Del(void (*)())
  std::shared_ptr<void()> x(Func, Del);

Where previously this would fail to compile. In PR27566, the use case described for this was a shared pointer to a dynamically loaded function, which seems reasonable enough to me. Both libstdc++ and MSVC support this use case as well, and I didn't notice any wording in the standard that disallowed it. This patch has 2 parts:

1. Don't try to instantiate an `allocator<T()>`
2. Fix `__enable_weak_this()` dummy overload to work with function pointers.

Number 1 is accomplished by passing in `allocator<void>` into `__shared_ptr_pointer` or `__shared_ptr_emplace` when no allocator was passed to the constructor of the `shared_ptr`, I believe this is correct because in this case the allocator is only used for a rebind, so any instantiation of std::allocator would work fine.

This is my first libc++ patch, so take it with a grain of salt! Thanks for taking a look,
Erik


https://reviews.llvm.org/D30837

Files:
  include/memory
  test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30837.91358.patch
Type: text/x-patch
Size: 7619 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170310/ec7606dc/attachment.bin>


More information about the cfe-commits mailing list