Boost C++ Libraries: Ticket #12272: vertex_iterator dereference has odd return value https://svn.boost.org/trac10/ticket/12272 <p> graph_traits::vertex_iterator::operator* seems to not return Value&amp; as it should. This not only differs from STL iterators but can and does easily cause segfaults. </p> <div class="wikipage" style="font-size: 80%"><p> Code highlighting: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span><span class="cpf">&lt;list&gt;</span><span class="cp"></span> <span class="cp">#include</span><span class="cpf">&lt;boost/graph/adjacency_list.hpp&gt;</span><span class="cp"></span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">adjacency_list</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">vecS</span><span class="p">,</span><span class="n">boost</span><span class="o">::</span><span class="n">vecS</span><span class="o">&gt;</span> <span class="n">Graph</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">graph_traits</span><span class="o">&lt;</span><span class="n">Graph</span><span class="o">&gt;::</span><span class="n">vertex_descriptor</span> <span class="n">Vertex</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">graph_traits</span><span class="o">&lt;</span><span class="n">Graph</span><span class="o">&gt;::</span><span class="n">vertex_iterator</span> <span class="n">VIter</span><span class="p">;</span> <span class="k">const</span> <span class="n">Vertex</span><span class="o">&amp;</span> <span class="n">deref</span><span class="p">(</span><span class="k">const</span> <span class="n">VIter</span><span class="o">&amp;</span> <span class="n">it</span><span class="p">){</span> <span class="k">return</span> <span class="o">*</span><span class="n">it</span><span class="p">;</span> <span class="c1">// warning: returning reference to temporary [-Wreturn-local-addr]</span> <span class="p">}</span> <span class="k">const</span> <span class="n">Vertex</span><span class="o">&amp;</span> <span class="n">deref</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">list</span><span class="o">&lt;</span><span class="n">Vertex</span><span class="o">&gt;::</span><span class="n">iterator</span><span class="o">&amp;</span> <span class="n">it</span><span class="p">){</span> <span class="k">return</span> <span class="o">*</span><span class="n">it</span><span class="p">;</span> <span class="c1">// no warning, works fine</span> <span class="p">}</span> <span class="kt">int</span> <span class="n">main</span><span class="p">(){</span> <span class="n">Graph</span> <span class="n">g</span><span class="p">;</span> <span class="n">Vertex</span> <span class="n">u</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">add_vertex</span><span class="p">(</span><span class="n">g</span><span class="p">);</span> <span class="n">Vertex</span> <span class="n">v</span> <span class="o">=</span> <span class="n">deref</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">vertices</span><span class="p">(</span><span class="n">g</span><span class="p">).</span><span class="n">first</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">list</span><span class="o">&lt;</span><span class="n">Vertex</span><span class="o">&gt;</span> <span class="n">vl</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">u</span><span class="p">);</span> <span class="n">Vertex</span> <span class="n">w</span> <span class="o">=</span> <span class="n">deref</span><span class="p">(</span><span class="n">vl</span><span class="p">.</span><span class="n">begin</span><span class="p">());</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12272 Trac 1.4.3