Visual Studio is correct. You are getting an assertion (in debug only!) because your code has undefined behaviour, and the implementation is warning you about that.
Value-initialised iterators can only be compared to other value-initialised iterators. This is a generalisation of the rule that comparing pointers or iterators only works within a sequence or array (with one notable exception being std::less
, which handily provides a total ordering over the whole memory space; this is the only way a set, using the default comparator, of unrelated pointers can work).
[forward.iterators] The domain of == for forward iterators is that of iterators over the same underlying sequence. However, value-initialized iterators may be compared and shall compare equal to other value-initialized iterators of the same type. [ Note: Value-initialized iterators behave as if they refer past the end of the same empty sequence. — end note ]
No semantics are defined for an ordering between a value-initialised iterator, and an iterator to a position in a sequence.
The cppreference text is a little badly-worded in this regard, though the same page does do a little better on the semantics for a successful equality between two singular iterators:
A value-initialized LegacyForwardIterator behaves like the past-the-end iterator of some unspecified empty container: it compares equal to all value-initialized LegacyForwardIterators of the same type.
And, again, you cannot compare iterators to different containers, so there we have our rule.