Opened 10 years ago

Closed 10 years ago

#7869 closed Bugs (invalid)

boost::in_edges bug

Reported by: ny_218@… Owned by: Jeremiah Willcock
Milestone: To Be Determined Component: graph
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc:

Description

The following code will generate an exception in Visual Studio 2010:

#include <boost/graph/adjacency_list.hpp>
#include <iostream>

int main()
{
  typedef boost::adjacency_list<
    boost::listS,
    boost::vecS,
    boost::bidirectionalS> graph_t;

  graph_t myGraph;
  graph_t::vertex_descriptor v1 = boost::add_vertex(myGraph);
  graph_t::vertex_descriptor v2 = boost::add_vertex(myGraph);
  boost::remove_vertex(v1, myGraph);
  boost::graph_traits<graph_t>::in_edge_iterator itEdge, itEnd;
  boost::tie(itEdge, itEnd) = boost::in_edges(v2, myGraph);
  for(; itEdge != itEnd; ++itEdge) {
    std::cout << boost::source(*itEdge, myGraph) << std::endl;
  }
  return 0;
}

Change History (1)

comment:1 by Jeremiah Willcock, 10 years ago

Resolution: invalid
Status: newclosed

When you remove the vertex v1, the vertex descriptor v2 is invalidated and thus no longer usable in operations such as in_edges. See the "Iterator and Descriptor Stability/Invalidation" section of http://www.boost.org/libs/graph/doc/adjacency_list.html for more information. One fix is to set your vertex container to listS instead of vecS.

Note: See TracTickets for help on using tickets.