Passing const shared_ptr<T>& versus just shared_ptr<T> as parameter
<p>I've been reading quite a number of discussions about performance issues when smart pointers are involved in an application. One of the frequent recommendations is to pass a smart pointer as const&amp; instead of a copy, like this:</p>

<pre><code>void doSomething(std::shared_ptr&lt;T&gt; o) {}
</code></pre>

<p>versus</p>

<pre><code>void doSomething(const std::shared_ptr&lt;T&gt; &amp;o) {}
</code></pre>

<p>However, doesn't the second variant actually defeat the purpose of a shared pointer? We are actually sharing the shared pointer here, so if for some reasons the pointer is released in the calling code (think of reentrancy or side effects) that const pointer becomes invalid. A situation the shared pointer actually should prevent. I understand that const&amp; saves some time as there is no copying involved and no locking to manage the ref count. But the price is making the code less safe, right?</p>