This is the mail archive of the
mailing list for the libstdc++ project.
Re: [PATCH] Fix PR libstdc++/19510: Uninitialized variable in some iterators
Chris Jefferson <firstname.lastname@example.org> writes:
| >But copying singular iterators is explicitly disallowed, isn't it?
| > Iterators can also have singular values that are not associated with
| > any container. [Example: After the declaration of an uninitialized
| > pointer x (as with int* x;), x must always be assumed to have a
| > singular value of a pointer. ] Results of most expressions are
| > undefined for singular values; the only exception is an assignment of
| > a nonsingular value to an iterator that holds a singular value. In
| > this case the singular value is overwritten the same way as any other
| > value.
| >This explicitly mentions the case of uninitialised pointers being
| Just a quick note. 8.3.1/2, the line "pc = p", shows you can copy
| uninitalised pointers.
You can write any code you want, it does not mean they have valid
meaning. As a matter of fact GCC would warn if you copy an
unintialized pointer. And rightly so. Being a pointer is no special
about that. Please consult 4.1/1
An lvalue (3.10) of a non-function, non-array type T can be
converted to an rvalue. If T is an incomplete type, a program that
necessitates this conversion is ill-formed. If the object to which
the lvalue refers is not an object of type T and is not an object of
a type derived from T, or if the object is uninitialized, a program
that necessitates this conversion has undefined behavior. If T is a
non-class type, the type of the rvalue is the cv-unqualified version
of T. Otherwise, the type of the rvalue is T.
The only exception is a char (and varints).