Shared pointer constness in comparison operator ==
问题 I stumbled upon an unexpected behavior of a shared pointer I'm using. The shared pointer implements reference counting and detaches (e.g. makes a copy of), if neccessary, the contained instance on non-const usage. To achieve this, for each getter function the smart pointer has a const and a non-const version, for example: operator T *() and operator T const *() const . Problem: Comparing the pointer value to nullptr leads to a detach. Expected: I thought that the comparison operator would