The assignment of a default constructed vector
errors on Visual Studio 2010. I\'ve tried this on 5 Visual Studio 2010 systems that all h
This code has undefined behavior. [iterator.requirements.general]/p6:
Iterators can also have singular values that are not associated with any sequence. [ Example: After the declaration of an uninitialized pointer
x
(as withint* x;
),x
must always be assumed to have a singular value of a pointer. —end example ] Results of most expressions are undefined for singular values; the only exceptions are destroying an iterator that holds a singular value, the assignment of a non-singular value to an iterator that holds a singular value, and, for iterators that satisfy theDefaultConstructible
requirements, using a value-initialized iterator as the source of a copy or move operation. [ Note: This guarantee is not offered for default initialization, although the distinction only matters for types with trivial default constructors such as pointers or aggregates holding pointers. —end note ] In these cases the singular value is overwritten the same way as any other value. Dereferenceable values are always non-singular.
uninitialized
is singular, and its use doesn't fall within any of the exceptions listed in the paragraph.
However, given the snippets you post, I suspect that your code wouldn't work either even if you value-initialize uninitialized
, which is a bug in Microsoft's implementation, and which they fixed in a later hotfix.