I had a typo in code recently, that was causing an infinite loop in some cases (but not in all environments, it seems).
It looked like this:
for (std::vector<myString>::iterator iter = myVector.begin(); iter != myVector.end(); ++iter = iter)
{
...
}
The typo is the assignment of the iterator to itself. Removing it fixes the issues.
I am wondering what exactly happens during the statement ++iter = iter?
I thought that according to operator precedence, iterator should first be incremented, then assigned to self, but I seem to be missing some steps (otherwise there would not be infinite loops).
My feeling is that it also involves dereferencing of the variable, but I am not sure to completely understand what was happening with this bug.
Also, why did it seem to not cause infinite loops on some platforms?