shared_ptr strangeness with null values and custom deleter : <p>We recently came across a crash when moving from a unique_ptr to a shared_ptr, using a custom deleter. The crash happened when the pointer used to create the smart pointer was null. Below is code that reproduces the problem, and shows two cases that work.</p>

<p>In the source below, One and Two run happily, while Three crashes in "ReleaseDestroy". The crash appears to be happening when the class being used in  the smart pointer has a virtual "Release" and so the program is trying to look up the V-Table. unique_ptr looks like it checks for null pointers and doesn't run the destructor. Shared pointer seems to neglect this. </p>

<p>Does anyone know if this is by design, or is it a bug in the stl implementation? We are using Visual Studio 2015.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;memory&gt;

template&lt;class R&gt;
void ReleaseDestroy(R* r)
{
    r-&gt;Release();
};

class FlatDestroy
{
public :
    void Release()
    {
        delete this;
    }
};

class VirtualDestroy
{
public:
    virtual void Release()
    {
        delete this;
    }
};

class SimpleOne
{
public :
};

void main()
{
    std::shared_ptr&lt;SimpleOne&gt; One(nullptr);
    std::shared_ptr&lt;FlatDestroy&gt; Two(nullptr, ReleaseDestroy&lt;FlatDestroy&gt;);
    std::shared_ptr&lt;VirtualDestroy&gt; Three(nullptr, ReleaseDestroy&lt;VirtualDestroy&gt;);

    One.reset();
    Two.reset();
    Three.reset();
}
</code></pre>
