gdb
is probably getting confused by an implementation detail the std::list
. E.g. the old SGI STL list
was implemented as a circular list. Inside the list
object, there is only a singly _List_node<_Tp>
pointer called _M_node
. The constructor puts the internal _M_next
pointer of the final node element equal to _M_node
itself.
The reason Standard Library implementations of std::list
use this circular implementation is to avoid special cases for the final element (e.g. they could also use a a sentinel element with a nullptr
next pointer). Matt Austern has a nice ACCU presentation about this (but the link is currently to a corrupted file, see archived version here).
This circular implementation explains why your gdb
output for g.neighbors()
has the repeating pattern of [0] = 2, [1] = 1, [2] = 4294956560, /* etcetera */
. The value 4294956560 is simply the memory address of the internal _M_node
variable of your std::list
, so if gdb
only does simnple pointer chasing, it will get confused. Notice that it is less than 2^32
, i.e. you are probably compiling this for 32-bits.
You should probably verify this in your own <list>
header of the Standard Library on your system. A bug report for gdb
might also be in order.