title: Boost Graph Library - crash in topological_sort with remove_vertex
body: <p>The following piece of code crashes in topological_sort with what appears to be corruption. Can anyone spot something in the code that could be causing this ? Or is it triggering a bug in BGL ?</p>
  
  <pre><code>#include &lt;boost/graph/graph_traits.hpp&gt;                                         
  #include &lt;boost/graph/adjacency_list.hpp&gt;                                       
  #include &lt;boost/graph/topological_sort.hpp&gt;                                     
  
  using namespace boost;                                                          
  
  typedef boost::adjacency_list &lt;listS, listS, bidirectionalS,                    
          boost::property&lt;boost::vertex_index_t, int &gt; &gt; Graph;                   
  typedef boost::graph_traits&lt;Graph&gt;::vertex_descriptor Vertex;                   
  typedef boost::graph_traits&lt;Graph&gt;::edge_descriptor Edge;                       
  
  int main(int,char*[])                                                           
  {                                                                               
      Graph graph;                                                                
      std::list&lt;Vertex&gt; vertex_list;                                              
      typedef property_map&lt;Graph, vertex_index_t&gt;::type index_map_t;              
      index_map_t index_map = get(vertex_index, graph);                           
      Vertex a, b, c, d, e, f, g;                                                 
      graph_traits&lt;Graph&gt;::vertices_size_type current_index = 0;                  
  
      a = add_vertex(graph);                                                      
      index_map[a] = current_index++;                                             
      b = add_vertex(graph);                                                      
      index_map[b] = current_index++;                                             
      c = add_vertex(graph);                                                      
      index_map[c] = current_index++;                                             
      d = add_vertex(graph);                                                      
      index_map[d] = current_index++;                                             
      e = add_vertex(graph);                                                      
      index_map[e] = current_index++;                                             
      clear_vertex(a, graph);                                                     
      remove_vertex(a, graph);                                                    
      f = add_vertex(graph);                                                      
      index_map[f] = current_index++;                                             
      g = add_vertex(graph);                                                      
      index_map[g] = current_index++;                                             
      topological_sort(graph, std::front_inserter(vertex_list));                  
  }                                                                               
  </code></pre>
  
  <p>Backtrace from the crash is as follows:</p>
  
  <pre><code>#0  0x00007ffff7538425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
  #1  0x00007ffff753bb8b in abort () from /lib/x86_64-linux-gnu/libc.so.6
  #2  0x00007ffff757639e in ?? () from /lib/x86_64-linux-gnu/libc.so.6
  #3  0x00007ffff7580b96 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
  #4  0x0000000000407e58 in boost::checked_array_delete&lt;boost::default_color_type&gt; (x=0x610290) at /usr/include/boost/checked_delete.hpp:41
  #5  0x0000000000407d54 in boost::checked_array_deleter&lt;boost::default_color_type&gt;::operator() (this=0x6102c8, x=0x610290)
      at /usr/include/boost/checked_delete.hpp:63
  #6  0x0000000000407f45 in boost::detail::sp_counted_impl_pd&lt;boost::default_color_type*, boost::checked_array_deleter&lt;boost::default_color_type&gt; &gt;::dispose (
      this=0x6102b0)
      at /usr/include/boost/smart_ptr/detail/sp_counted_impl.hpp:148
  #7  0x0000000000401ab6 in boost::detail::sp_counted_base::release (
      this=0x6102b0)
      at /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:145
  #8  0x0000000000401b2f in boost::detail::shared_count::~shared_count (
      this=0x7fffffffe418, __in_chrg=&lt;optimized out&gt;)
      at /usr/include/boost/smart_ptr/detail/shared_count.hpp:305
  #9  0x0000000000403786 in boost::shared_array&lt;boost::default_color_type&gt;::~shared_array (this=0x7fffffffe410, __in_chrg=&lt;optimized out&gt;)
      at /usr/include/boost/smart_ptr/shared_array.hpp:46
  #10 0x00000000004037a0 in boost::shared_array_property_map&lt;boost::default_color_type, boost::adj_list_vertex_property_map&lt;boost::adjacency_list&lt;boost::listS, boost::listS, boost::bidirectionalS, boost::property&lt;boost::vertex_index_t, int, boost::no_property&gt;, boost::no_property, boost::no_property, boost::listS&gt;, int, int const&amp;, boost::vertex_index_t&gt; &gt;::~shared_array_property_map (
      this=0x7fffffffe410, __in_chrg=&lt;optimized out&gt;)
      at /usr/include/boost/property_map/shared_array_property_map.hpp:19
  #11 0x0000000000403997 in boost::depth_first_search&lt;boost::adjacency_list&lt;boost::listS, boost::listS, boost::bidirectionalS, boost::property&lt;boost::vertex_index_t, int, boost::no_property&gt;, boost::no_property, boost::no_property, boost::listS&gt;, boost::topo_sort_visitor&lt;std::front_insert_iterator&lt;std::list&lt;void*, std::allocator&lt;void*&gt; &gt; &gt; &gt;, boost::graph_visitor_t, boost::bgl_named_params&lt;int, boost::buffer_param_t, boost::no_property&gt; &gt; (g=..., params=...)
      at /usr/include/boost/graph/depth_first_search.hpp:298
  #12 0x0000000000402e6f in boost::topological_sort&lt;boost::adjacency_list&lt;boost::listS, boost::listS, boost::bidirectionalS, boost::property&lt;boost::vertex_index_t, int, boost::no_property&gt;, boost::no_property, boost::no_property, boost::listS---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---
  &gt;, std::front_insert_iterator&lt;std::list&lt;void*, std::allocator&lt;void*&gt; &gt; &gt;, int, boost::buffer_param_t, boost::no_property&gt; (g=..., result=..., params=...)
      at /usr/include/boost/graph/topological_sort.hpp:65
  #13 0x00000000004024d6 in boost::topological_sort&lt;boost::adjacency_list&lt;boost::listS, boost::listS, boost::bidirectionalS, boost::property&lt;boost::vertex_index_t, int, boost::no_property&gt;, boost::no_property, boost::no_property, boost::listS&gt;, std::front_insert_iterator&lt;std::list&lt;void*, std::allocator&lt;void*&gt; &gt; &gt; &gt; (
      g=..., result=...) at /usr/include/boost/graph/topological_sort.hpp:71
  #14 0x00000000004015c5 in main () at bgl_try.cc:40
  </code></pre>