Does shared_ptr member have a CopyConstructible contract break?

I just had an argument in codereview where it was pointed out that a class having a member std::shared_ptrwould break CopyConstructible , in particular:

The following expressions must be valid and have the indicated effects.

T u = v;

V value does not change

The reason was that copying would change the original object by increasing the reference count shared_ptr, but my counter argument is that the reference count is kept separate from shared_ptr. Changing the reference counter is a side effect, but the link does not indicate that side effects outside the copied object are prohibited.

But then I’m not a language lawyer, so I can be wrong.

What is correct according to the C ++ standard?

+4
source share
1 answer

V value does not change

The value of the object is what you say.

The reason was that copying would change the original object by increasing the number of links to shared_ptr, but my counter-argument is that the reference count is stored separately from shared_ptr.

If the counter is stored or it is stored somewhere else, it is beyond the scope of the standard.

+2
source

Source: https://habr.com/ru/post/1678963/


All Articles