Created on 2016-04-02.00:00:00 last changed 90 months ago
Proposed resolution:
This wording is relative to N4582.
Change [util.smartptr.shared.create] indicated:
template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args); template<class T, class A, class... Args> shared_ptr<T> allocate_shared(const A& a, Args&&... args);[…]
-6- Remarks: The shared_ptr constructor called by this function enables shared_from_this with the address of the newly constructed object of type T. Implementations should perform no more than one memory allocation. [Note: This provides efficiency equivalent to an intrusive smart pointer. — end note]
[ 2016-08 Chicago ]
Monday PM: Move to Tentatively Ready
[ 2016-05 Issues Telecon ]
Jonathan Wakely to provide updated wording.
For each public constructor of std::shared_ptr, the standard says that constructor enables shared_from_this if that constructor is expected to initialize the internal weak_ptr of a contained enable_shared_from_this<X> object. But there are other ways to construct a shared_ptr than by using a public constructor. The template functions make_shared and allocate_shared both require calling a private constructor, since no public constructor can fulfill the requirement that at most one allocation is made. The standard does not specify that that private constructor enables shared_from_this; therefore in the following code:
struct Foo : public std::enable_shared_from_this<Foo> {}; int main() { auto p = std::make_shared<Foo>(); assert(p == p->shared_from_this()); return 0; }
it is unspecified whether the assertion will fail.
History | |||
---|---|---|---|
Date | User | Action | Args |
2017-07-30 20:15:43 | admin | set | status: wp -> c++17 |
2016-11-14 03:59:28 | admin | set | status: pending -> wp |
2016-11-14 03:55:22 | admin | set | status: ready -> pending |
2016-08-02 17:19:11 | admin | set | messages: + msg8333 |
2016-08-02 17:19:11 | admin | set | status: new -> ready |
2016-05-22 15:38:38 | admin | set | messages: + msg8140 |
2016-05-07 20:27:58 | admin | set | messages: + msg8090 |
2016-04-02 00:00:00 | admin | create |