title: Mysterious crash with shared_ptr
body: <p>Can someone please explain why the following crashes in main() when the inner scope is exited?  I'm using Visual Studio 2013.  Though everything is fine with GCC 4.8.1, I suspect something is wrong in the code anyway.  I just don't get it.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  class Person;  class PersonProxy;
  
  class PersonInterface {
      public:
          virtual ~PersonInterface() = default;
          virtual PersonProxy* getProxy() const = 0;
          virtual void createProxy (Person*) = 0;
      };
  
  class Person : public PersonInterface {
      private:
          std::string name;
          std::shared_ptr&lt;PersonProxy&gt; proxy;
      public:
          Person() = default;
          explicit Person (const std::string&amp; n) : name(n) {}
      public:
          virtual PersonProxy* getProxy() const override {return proxy.get();}
          inline void createProxy (Person* p);
  };
  
  class PersonProxy : public PersonInterface {
      private:
          std::shared_ptr&lt;Person&gt; actual;
      public:
          explicit PersonProxy (Person* p) : actual (std::shared_ptr&lt;Person&gt;(p)) {}
          explicit PersonProxy (std::shared_ptr&lt;Person&gt; p) : actual (p) {}
          void rebind (std::shared_ptr&lt;Person&gt; p) {actual = p;}
          virtual PersonProxy* getProxy() const override {return actual-&gt;getProxy();}
          virtual void createProxy (Person* p) override {actual-&gt;createProxy(p);}
  };
  
  class Girl : public Person {
      public:
          Girl (const std::string&amp; name) : Person (name) {createProxy (this);}
  };
  
  inline void Person::createProxy (Person* p) {
      proxy = std::shared_ptr&lt;PersonProxy&gt;(new PersonProxy(p));
  }
  
  int main() {
      {
          Girl* a = new Girl("a");
  //      std::shared_ptr&lt;Girl&gt; a = std::make_shared&lt;Girl&gt;("a");  // Using this crashes with Visual Studio 2013 on the line 'a-&gt;getProxy()-&gt;rebind(b);'
          std::shared_ptr&lt;Girl&gt; b = std::make_shared&lt;Girl&gt;("b");
          a-&gt;getProxy()-&gt;rebind(b);
          std::cout &lt;&lt; "rebind succeeded." &lt;&lt; std::endl;
      }
      std::cout &lt;&lt; "Exited scope." &lt;&lt; std::endl;  // Exiting scope crashes with VS 2013.
  }
  </code></pre>
  
  <p>The error message I get with VS2013 is:</p>
  
  <p>assertion failure</p>
  
  <p>_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)</p>