shared_ptr::shared_ptr(Y*, D, […]) constructors should be constrainedSection: 20.3.2.2.2 [util.smartptr.shared.const] Status: C++17 Submitter: United States Opened: 2017-02-03 Last modified: 2020-09-06
Priority: Not Prioritized
View other active issues in [util.smartptr.shared.const].
View all other issues in [util.smartptr.shared.const].
View all issues with C++17 status.
Discussion:
Addresses US 126
Paragraph 8: This constructor should not participate in overload
resolution unless the Requires clause is satisfied.
Note that this would therefore apply to some assignment operator and
reset overloads, via Effects: equivalent to some code wording.
Proposed change:
Add a Remarks: clause to constrain this constructor not to participate in overload resolution unless the Requires clause is satisfied.
[2017-02 pre-Kona]
See US 125: LWG 2874.
[2017-02-23, Jonathan provides wording]
This wording is relative to N4640.
Modify 20.3.2.2.2 [util.smartptr.shared.const] as indicated:
If the proposed resolution of LWG 2802 has been accepted modify p8 as shown:
template<class Y, class D> shared_ptr(Y* p, D d); template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); template <class D> shared_ptr(nullptr_t p, D d); template <class D, class A> shared_ptr(nullptr_t p, D d, A a);-8- Requires:
Construction ofDshall beMoveConstructibleand cdand a deleter of typeDinitialized withstd::move(d)shall not throw exceptions. The expressiond(p)shall be well formed,shall have well-defined behavior, and shall not throw exceptions.Ashall be an allocator (17.5.3.5).WhenTisU[N],Y(*)[N]shall be convertible toT*; whenTisU[],Y(*)[]shall be convertible toT*; otherwise,Y*shall be convertible toT*.
If the proposed resolution of LWG 2802 has not been accepted modify p8 as shown:
template<class Y, class D> shared_ptr(Y* p, D d); template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); template <class D> shared_ptr(nullptr_t p, D d); template <class D, class A> shared_ptr(nullptr_t p, D d, A a);-8- Requires:
Construction ofDshall beCopyConstructibleand such cdand a copy ofdshall not throw exceptions. The destructor ofDshall not throw exceptions. The expressiond(p)shall be well formed,shall have well defined behavior, and shall not throw exceptions.Ashall be an allocator (17.5.3.5). The copy constructor and destructor ofAshall not throw exceptions.WhenTisU[N],Y(*)[N]shall be convertible toT*; whenTisU[],Y(*)[]shall be convertible toT*; otherwise,Y*shall be convertible toT*.
In either case, add a Remarks paragraph after p11:
[Drafting note: If LWG 2802 is not accepted, replace
is_move_constructible_vwithis_copy_constructible_v.]
template<class Y, class D> shared_ptr(Y* p, D d); template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); template <class D> shared_ptr(nullptr_t p, D d); template <class D, class A> shared_ptr(nullptr_t p, D d, A a);-8- Requires: […]
[…] -11- Throws: […] -?- Remarks: WhenTis an array type, this constructor shall not participate in overload resolution unlessis_move_constructible_v<D>istrue, the expressiond(p)is well-formed, and eitherTisU[N]andY(*)[N]is convertible toT*, orY(*)[]is convertible toT*. WhenTis not an array type, this constructor shall not participate in overload resolution unlessis_move_constructible_v<D>istrue, the expressiond(p)is well-formed, andY*is convertible toT*.
[Kona 2017-02-27: Jonathan updates wording after LWG review]
[Kona 2017-02-27]
Accepted as Immediate to resolve NB comment.
Proposed resolution:
This wording is relative to N4640 as modified by the proposed resolution of LWG 2802.
Modify 20.3.2.2.2 [util.smartptr.shared.const] as indicated:
template<class Y, class D> shared_ptr(Y* p, D d); template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); template <class D> shared_ptr(nullptr_t p, D d); template <class D, class A> shared_ptr(nullptr_t p, D d, A a);-8- Requires:
Construction ofDshall beMoveConstructibleand cdand a deleter of typeDinitialized withstd::move(d)shall not throw exceptions. The expressiond(p)shall be well formed,shall have well-defined behavior, and shall not throw exceptions.Ashall be an allocator (17.5.3.5).WhenTisU[N],Y(*)[N]shall be convertible toT*; whenTisU[],Y(*)[]shall be convertible toT*; otherwise,Y*shall be convertible toT*.
Add a Remarks paragraph after p11:
template<class Y, class D> shared_ptr(Y* p, D d); template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); template <class D> shared_ptr(nullptr_t p, D d); template <class D, class A> shared_ptr(nullptr_t p, D d, A a);-8- Requires: […]
[…] -11- Throws: […] -?- Remarks: WhenTis an array type, this constructor shall not participate in overload resolution unlessis_move_constructible_v<D>istrue, the expressiond(p)is well-formed, and eitherTisU[N]andY(*)[N]is convertible toT*, orTisU[]andY(*)[]is convertible toT*. WhenTis not an array type, this constructor shall not participate in overload resolution unlessis_move_constructible_v<D>istrue, the expressiond(p)is well-formed, andY*is convertible toT*.