title: How can std::set::erase(const key_type& key) cause segfault?
body: <p>I'm tracking a bug and I run into very strange behaviour. I have set of pointers and when I erase them one-by-one, first one erases, but erasing another gives me segfault.
  I use </p>
  
  <pre><code>   size_type erase( const key_type&amp; key );
  </code></pre>
  
  <p>so it can't be something with iterators. My debuger shows me that in callstack:</p>
  
  <pre><code>0 - std::less&lt;cSubscriber *&gt;::operator() //cSubscriber is an abstract base class and I have a set of cSubscriber *
  
  1 - std::_Rb_tree&lt;cSubscriber*, cSubscriber*, std::_Identity&lt;cSubscriber*&gt;, std::less&lt;cSubscriber*&gt;, std::allocator&lt;cSubscriber*&gt; &gt;::equal_range
  
  2 -  std::_Rb_tree&lt;cSubscriber*, cSubscriber*, std::_Identity&lt;cSubscriber*&gt;, std::less&lt;cSubscriber*&gt;, std::allocator&lt;cSubscriber*&gt; &gt;::erase
  
  3 - std::set&lt;cSubscriber*, std::less&lt;cSubscriber*&gt;, std::allocator&lt;cSubscriber*&gt; &gt;::erase
  
  4 - cEventSystem::unsubscribe //my function, it is as follows in the class which has the set as its member
  
  cEventSystem::unsubscribe(cSubscriber * ptr)
  {
     set.erase(ptr);
  }
  </code></pre>
  
  <p>And in the base cSubscriber abstract class there is virtual destructor:</p>
  
  <pre><code>  virtual ~cSubscriber()
    {
        eventSystem.unsubscribe(this);
    }
  </code></pre>
  
  <p>Any ideas? I have no idea how can it cause segfault, the erase should just return 0 when there isn't such an element. Or maybe it crashesh when trying to erase something from empty container? (I have another bug when after adding 3 differents pointers the size of set is only 2 but that's another story).</p>