title: Trivial cases of shared_ptr and weak_ptr failing
body: <p>I'm having trouble using <code>shared_ptr</code> and <code>weak_ptr</code> along with <code>enable_shared_from_this</code>.</p>
  
  <p>When I google the symptoms of what I'm seeing, everybody suggests "you cannot use <code>shared_from_this()</code> when there are no <code>shared_ptr</code> instances owning your object.</p>
  
  <p>But that's not my case.</p>
  
  <p>Consider this code:</p>
  
  <pre><code>#include &lt;memory&gt;
  #include &lt;cassert&gt;
  
  class MyClass : std::enable_shared_from_this&lt;MyClass&gt;
  {
  public:
      void this_fails()
      {
          // Doesn't even assert(), because it throws bad_weak_ptr
          assert(shared_from_this());
      }
      void this_fails_too()
      {
          std::weak_ptr&lt;MyClass&gt; weak = weak_from_this();
          std::shared_ptr&lt;MyClass&gt; strong = weak.lock();
          // This assert fails
          assert(strong.get());
      }
  };
  
  int main()
  {
      std::shared_ptr&lt;MyClass&gt; obj = std::make_shared&lt;MyClass&gt;();
  
      obj-&gt;this_fails();
      obj-&gt;this_fails_too();
  }
  
  </code></pre>
  
  <p>Both methods in <code>MyClass</code> crash the program. I must be missing something obvious - what is it?</p>