To find the reason, turn on debugging symbols, and when you get to the first line, first check the contents of b, which looks like this (the value will differ). In this case, I used Code :: Blocks "Watch", an option.
b.M_Impl._M_node._M_next = 0x7fffffffe370 b.M_Impl._M_node._M_prev = 0x7fffffffe370
Then use the debugger option for "Stand up" as soon as we click on our line b.size.
In the end, this will lead us to stl_iterator_base_funcs.h
In the beginning we see that the first and last are the same:
__first._M_node = 0x7fffffffe370 __last._M_node = 0x7fffffffe370 while (__first != __last) { ++__first; ++__n; }
Entering ++__first , we see that he does this in stl_list.h:
_Self& operator++() { _M_node = _M_node->_M_next; return *this; }
_M_node and _M_node->_M_next same, so __first never grows, and .size() gets into an infinite loop.
source share