<p>I have an old project that was built using visual studio 2003 and I recompiled it with vs2005 recently.  However, during runtime, I get the following error:</p>

<p>list iterator not incrementable</p>

<p>I traced the program to this function:</p>

<pre><code>void InputQueue::update()
{
    list&lt;PCB&gt;::iterator iter;
    list&lt;PCB&gt;::iterator iterTemp;
    for(iter = begin(); iter != end(); iter++)
    {
        if(iter-&gt;arrivalTime == 0)
        {           
            ReadyQueue::getInstance()-&gt;add(*iter);
            iterTemp = iter;
            iter++;
            erase(iterTemp);
        }
    }
}
</code></pre>

<p>I'm not a C++ expert and this is as far as the VS debugger got me.  Could somebody explain to me what the problem is?</p>

<p>Thanks</p>

Notice that if
```
iter->arrivalTime == 0
```
, then the list iterator gets incremented twice: once before element removal, and once again at the end of the loop.
If the item to be removed is the last item in the list, this will obviously not work correctly. I dare say that it never did work correctly even in VS2003, but VS2005 alerts you about it better. :-)
Remember, it's undefined behaviour to iterate past
```
end()
```
. Absolutely anything can happen, such as program crash, or (in this case) an error message.