[PATCH] Fix PR libstdc++/19510: Uninitialized variable in some iterators

Chris Jefferson caj@cs.york.ac.uk
Thu Jan 20 12:46:00 GMT 2005


Jonathan Wakely wrote:

>
>But copying singular iterators is explicitly disallowed, isn't it?
>
>24.1/5:
>   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
>singular.
>
>  
>
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?)

>>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.
>  
>
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.

Chris



More information about the Libstdc++ mailing list