Title
Annex C should mention shared_ptr changes for array support
Status
c++17
Section
[diff.cpp14.utilities]
Submitter
Jonathan Wakely

Created on 2016-10-18.00:00:00 last changed 89 months ago

Messages

Date: 2016-11-21.05:09:01

Proposed resolution:

This wording is relative to N4606.

  1. Add to [diff.cpp14.utilities]:

    [util.smartptr.shared]

    Change: Different constraint on conversions from unique_ptr.

    Rationale: Adding array support to shared_ptr, via the syntax shared_ptr<T[]> and shared_ptr<T[N]>.

    Effect on original feature: Valid code may fail to compile or change meaning in this International Standard. For example:

    #include <memory>
    std::unique_ptr<int[]> arr(new int[1]);
    std::shared_ptr<int> ptr(std::move(arr)); // error: int(*)[] is not compatible with int*
    
Date: 2016-11-15.00:00:00

[ 2016-11-12, Issaquah ]

Sat AM: Priority 0; move to Ready

Date: 2016-10-18.00:00:00

This is valid in C++11 and C++14:

shared_ptr<int> s{unique_ptr<int[]>{new int[1]}};

The shared_ptr copies the default_delete<int[]> deleter from the unique_ptr, which does the right thing on destruction.

In C++17 it won't compile, because !is_convertible_v<int(*)[], int*>.

The solution is to use shared_ptr<int[]>, which doesn't work well in C++14, so there's no transition path. This should be called out in Annex C.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2017-03-05 23:41:16adminsetstatus: ready -> wp
2016-11-21 05:09:01adminsetmessages: + msg8669
2016-11-21 05:09:01adminsetstatus: new -> ready
2016-10-31 20:29:21adminsetmessages: + msg8574
2016-10-18 00:00:00admincreate