Same address, multiple shared_ptr counters, is it forbidden by C++ standard?

Posted by icando on Stack Overflow See other posts from Stack Overflow or by icando
Published on 2012-06-18T09:07:27Z Indexed on 2012/06/18 9:16 UTC
Read the original article Hit count: 218

Filed under:
|
|

Suppose I have some needs to do the following (This is just some imaginative code for discussion of the C++ standard, thus I won't discuss why I design it this way, so don't bother me something like: your design is wrong.)

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

Suppose the logic guarantees that p or some of its copies lives longer than any copies of q, so practically there won't be any problem. My question is, is it forbidden by C++ standard, e.g. explicitly stated as UB by C++ standard, that different shared_ptr counters share the same address?

Thanks.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c++11