[PATCH] D30837: [libcxx] Support for shared_ptr<T()>
Erik Pilkington via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 14 05:45:45 PDT 2017
erik.pilkington added a comment.
In https://reviews.llvm.org/D30837#698305, @EricWF wrote:
> We can't just use an arbitrary allocator type for a number of reasons:
> - You just changed the type of the control block. That's ABI breaking.
Ah, I didn't think of that. This new patch only selects `allocator<int>` when _Yp is a function type, which is only permitted as of this patch.
> - `allocator<int>` allocates ints, nothing else.
Since we only use `allocator<int>` for a rebind, we don't violate this rule.
> - It may mean we don't select a valid user specialization of `allocator<Yp>`.
In the new patch, `allocator<int>` is only selected if `is_function<_Yp>`, I don't believe that there is any valid user specialization of `std::allocator<FunctionType>`. This is because [namespace.std] p1:
> A program may add a template specialization for any standard library template to namespace std only if [...] the specialization meets the standard library requirements for the original template [...]
In this case, the original template is the default allocator, which is supposed to have overloads of `address` taking a `const_reference` and a `reference` ([allocator.members] p2-3), which will be ambiguous for function types with the given definitions of `const_reference` and `reference`. Is this a valid argument?
More information about the cfe-commits