This behavior is undefined, which means that everything can happen, including segfault or what you experienced, or something else. Basically, you are just lucky that it is not a failure (or unsuccessful, based on a point of view).
The language does not require an iterator access check, since this will require a run-time check. C ++ usually tries to avoid unnecessary overhead at runtime, leaving the programmer to perform any checks.
Most modern platforms use paged virtual memory, which provides memory protection with an accuracy of several kilobytes. This means that there is often available memory after the allocated block (for example, one controlled by std :: vector), in which case calls outside the range will simply stomp in that memory.
Visual Studio is trying to help remove dangerous code. Basically, a pointer could point anywhere if you hadn't dereferenced it, but iterators are a higher-level abstraction and have the ability to detect whether dereferencing is valid and, therefore, increase errors at runtime. Visual Studio has done this with vector<T>::iterator since at least VS 2007.
source share