Opened 6 years ago
#12272 new Bugs
vertex_iterator dereference has odd return value
Reported by: | Owned by: | Jeremiah Willcock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | graph |
Version: | Boost 1.61.0 | Severity: | Problem |
Keywords: | Cc: |
Description
graph_traits::vertex_iterator::operator* seems to not return Value& as it should. This not only differs from STL iterators but can and does easily cause segfaults.
Code highlighting:
#include<list> #include<boost/graph/adjacency_list.hpp> typedef boost::adjacency_list<boost::vecS,boost::vecS> Graph; typedef boost::graph_traits<Graph>::vertex_descriptor Vertex; typedef boost::graph_traits<Graph>::vertex_iterator VIter; const Vertex& deref(const VIter& it){ return *it; // warning: returning reference to temporary [-Wreturn-local-addr] } const Vertex& deref(const std::list<Vertex>::iterator& it){ return *it; // no warning, works fine } int main(){ Graph g; Vertex u = boost::add_vertex(g); Vertex v = deref(boost::vertices(g).first); std::list<Vertex> vl(1, u); Vertex w = deref(vl.begin()); return 0; }
Note:
See TracTickets
for help on using tickets.