shared_ptr
changes for array supportSection: C.4.9 [diff.cpp14.utilities] Status: C++17 Submitter: Jonathan Wakely Opened: 2016-10-18 Last modified: 2017-07-30
Priority: 0
View all issues with C++17 status.
Discussion:
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.
!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.
[2016-11-12, Issaquah]
Sat AM: Priority 0; move to Ready
Proposed resolution:
This wording is relative to N4606.
Add to C.4.9 [diff.cpp14.utilities]:
20.3.2.2 [util.smartptr.shared]
Change: Different constraint on conversions fromunique_ptr
. Rationale: Adding array support toshared_ptr
, via the syntaxshared_ptr<T[]>
andshared_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*