Section: C.4.9 [diff.cpp14.utilities] Status: C++17 Submitter: Jonathan Wakely Opened: 2016-10-18 Last modified: 2017-07-30 20:15:43 UTC
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.
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.[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 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*