Title
shared_ptr deleters must not not throw on move construction
Status
c++17
Section
[util.smartptr.shared.const]
Submitter
Jonathan Wakely

Created on 2016-05-03.00:00:00 last changed 89 months ago

Messages

Date: 2016-05-03.16:48:10

Proposed resolution:

[Drafting note: the relevant expressions we're concerned about are enumerated in the CopyConstructible and MoveConstructible requirements, so I see no need to repeat them by saying something clunky like "Initialization of an object of type D from an expression of type (possibly const) D shall not throw exceptions", we can just refer to them. An alternative would be to define NothrowCopyConstructible, which includes CopyConstructible but requires that construction and destruction do not throw.]

Change [util.smartptr.shared.const] p8:

D shall be CopyConstructible and such construction shall not throw exceptions. The copy constructor and destructor of D shall not throw exceptions.

Date: 2016-05-03.00:00:00

In [util.smartptr.shared.const] p8 the shared_ptr constructors taking a deleter say:

The copy constructor and destructor of D shall not throw exceptions.

It's been pointed out that this doesn't forbid throwing moves, which makes it difficult to avoid a leak here:

struct D {
  D() = default;
  D(const D&) noexcept = default;
  D(D&&) { throw 1; }
  void operator()(int* p) const { delete p; }
};

shared_ptr<int> p{new int, D{}};

"The copy constructor" should be changed to reflect that the chosen constructor might not be a copy constructor, and that copies made using any constructor must not throw.

N.B. the same wording is used for the allocator argument, but that's redundant because the Allocator requirements already forbid exceptions when copying or moving.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2016-06-28 12:50:44adminsetstatus: ready -> wp
2016-05-22 15:38:38adminsetstatus: new -> ready
2016-05-03 16:48:10adminsetmessages: + msg8067
2016-05-03 00:00:00admincreate