Title
shared_ptr construction from unique_ptr should move (not copy) the deleter
Status
c++23
Section
[util.smartptr.shared.const]
Submitter
Thomas Köppe

Created on 2021-05-04.00:00:00 last changed 4 months ago

Messages

Date: 2021-06-07.16:58:04

Proposed resolution:

This wording is relative to N4885.

  1. Modify [util.smartptr.shared.const] as indicated:

    template<class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
    

    -28- Constraints: Y* is compatible with T* and unique_ptr<Y, D>::pointer is convertible to element_type*.

    -29- Effects: If r.get() == nullptr, equivalent to shared_ptr(). Otherwise, if D is not a reference type, equivalent to shared_ptr(r.release(), std::move(r.get_deleter())). Otherwise, equivalent to shared_ptr(r.release(), ref(r.get_deleter())). If an exception is thrown, the constructor has no effect.

Date: 2021-06-07.00:00:00

[ 2021-06-07 Approved at June 2021 virtual plenary. Status changed: Voting → WP. ]

Date: 2021-05-15.00:00:00

[ 2021-05-17; Reflector poll ]

Set status to Tentatively Ready after eight votes in favour during reflector poll.

Date: 2021-05-04.00:00:00

The construction of a shared_ptr from a suitable unique_ptr rvalue r (which was last modified by LWG 2415, but not in ways relevant to this issue) calls for shared_ptr(r.release(), r.get_deleter()) in the case where the deleter is not a reference.

This specification requires the deleter to be copyable, which seems like an unnecessary restriction. Note that the constructor unique_ptr(unique_ptr&& u) only requires u's deleter to be Cpp17MoveConstructible. By analogy, the constructor shared_ptr(unique_ptr<Y, D>&&) should also require D to be only move-, not copy-constructible.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2021-06-07 16:58:04adminsetmessages: + msg11911
2021-06-07 16:58:04adminsetstatus: voting -> wp
2021-05-26 21:11:22adminsetstatus: ready -> voting
2021-05-17 12:23:56adminsetmessages: + msg11807
2021-05-17 12:23:56adminsetstatus: new -> ready
2021-05-08 12:18:11adminsetmessages: + msg11791
2021-05-04 00:00:00admincreate