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:
- Don't try to instantiate an allocator<T()>
- 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,