The same address, several shared_ptr counters, is it forbidden by the C ++ standard?

Suppose I need to do the following (this is just some figurative code to discuss the C ++ standard, so I won’t discuss why I design it this way, so don’t bother me with something like: the design is wrong.)

T* ptr = new T;
shared_ptr<T> p(ptr);
shared_ptr<T> q(ptr, SomeDeleterThatDoesnotDeleteButDoSomeOtherStuff());

Suppose that logic guarantees that peither some of its copies live longer than all copies q, so there will be practically no problems. My question is whether it is prohibited by the C ++ standard, for example. explicitly indicated as UB by the C ++ standard, for different shared_ptr counters to share the same address?

Thank.

+5
source share
2 answers

- (, ), . , , 20.9.11.2.10 shared_ptr casts

5 [: shared_ptr (static_cast (r.get())) undefined, . - ]

, -, .

+2

shared_ptr , UB, , , .

, shared_ptr , , UB.

+5

All Articles