Check this code:
#include \"stdafx.h\"
#include
int _tmain(int argc, _TCHAR* argv[])
{
std::list mylist;
mylist.push_back(1);
Other answers point out that, in general, you can't rely on a container's past-the-end iterator remaining valid when the container is cleared. However, the past-the-end iterator of a list should indeed remain valid:
C++11 23.3.5.4/3 Effects: Invalidates only the iterators and references to the erased elements.
The past-the-end iterator does not refer to any element, so should not be invalidated.