This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] fix libstdc++/58659
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "libstdc++" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 8 Oct 2013 14:42:36 +0100
- Subject: Re: [patch] fix libstdc++/58659
- Authentication-results: sourceware.org; auth=none
- References: <CAH6eHdTHhreqWmmyFe4OZa+rPQV-dTHRzv_0HQWHQyh43_XbSQ at mail dot gmail dot com>
On 8 October 2013 13:33, Jonathan Wakely wrote:
> PR libstdc++/58659
> * include/bits/shared_ptr_base.h (__shared_count::__shared_count(P,D)):
> Delegate to constructor taking allocator.
> (__shared_count::_S_create_from_up): Inline into ...
> (__shared_count::__shared_count(unique_ptr<Y,D>&&): Here. Use
> std::conditional instead of constrained overloads. Allocate memory
> using the allocator type that will be used for deallocation.
> * testsuite/20_util/shared_ptr/cons/58659.cc: New.
> * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust.
>
> Tested x86_64-linux, committed to trunk.
I've committed the same change to the 4.8 branch, except that the
dummy allocator type passed by the delegating constructor to the
target constructor is std::allocator<int> instead of
std::allocator<void>:
+ __shared_count(_Ptr __p, _Deleter __d)
+ : __shared_count(__p, std::move(__d), allocator<int>())
+ { }
That's the type that was already used, so users will get the same
specialization of _Sp_counted_deleter with 4.8.2 as with 4.8.1.
On the trunk I changed it to std::allocator<void> to be consistent
with the type used when constructing from a unique_ptr. That should
mean slightly smaller executables in cases like this:
std::shared_ptr<X> sp1(new X, std::default_delete<X>());
std::shared_ptr<X> sp2(std::unique_ptr<X>(new X));
On trunk the same _Sp_counted_deleter specialization will be used by
sp1 and sp2.