<div dir="ltr">Hello!<div><br></div><div>I've stumbled upon a peculiarity with lists which I haven't been able to explain so far.</div><div><br></div><div>Consider the following code:</div><div><br></div><div>#include <list><br>#include <cstdio><br><br>int main() {<br>    std::list<int> l;<br>    std::list<int>::iterator it = l.begin();<br>    l.push_back(0);<br>    l.insert(it, 1);<br>    for(const int &i: l) {<br>        printf("%d", i);<br>    }<br>}<br></div><div><br></div><div>This will print "01". I fail to understand why the 1 is inserted at the end. I would expect that the begin iterator would stay valid across the `push_back`. For the record, g++ seems to have the same behavior.</div><div><br></div><div>I've already created a stack overflow question around this (<a href="https://stackoverflow.com/questions/59974821/validity-of-list-begin-iterator-after-insertion">https://stackoverflow.com/questions/59974821/validity-of-list-begin-iterator-after-insertion</a>) and asked in the llvm IRC channel about it. So far without having an explanation. So now I'm turning to you.</div><div><br></div><div>Thank you in advance</div><div><br></div><div>Alexander Torstling</div></div>