This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Fix PR libstdc++/19510: Uninitialized variable in someiterators
Jonathan Wakely wrote:
Thats interesting, I hadn't seen that before. Interestingly, that would
forbid this vector from ever extending or being passed by value to a
function. However I assume here the copying in question is some kind of
internal copying (I'm not an expert on the problem in question, but I
assume that static elements are defined in some kind of data block, and
then copied out of it?)
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
This explicitly mentions the case of uninitialised pointers being
Hmm.. I would tend to say the "C++" way was to never default initalise
anything unless you have to. However I noticed vector<>::iterator and
others default initalise, so I'll go with whatever more knowledgeable say.
copying an unassigned pointer, and I don't see what advantage is gained
by assigning the pointer, and the obvious (possibly slight) disadvantage
is that now we have an extra assignment.
We have a default-initialisation (to zero in this case), rather than an
indeterminate value. IMHO any slight overhead is worth it.