This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

On Thu, Jan 20, 2005 at 11:34:07AM +0000, Chris Jefferson wrote:

> Volker Reichelt wrote:
> >PR libstdc++/19510 is about a warning that is triggered from within the
> >libstdc++ headers. When compiling the following code snippet with
> >"-Wall -O3" using mainline
> >
> >===============================================
> >#include<vector>
> >#include<list>
> >
> >std::vector<std::list<int>::iterator> v(1);
> >===============================================
> >
> >the following warning is issued:
> >
> >/long_path/stl_construct.h: In function 'void
> >__static_initialization_and_destruction_0(int, int)':
> >/long_path/stl_construct.h:81: warning: 'SR.133' is used uninitialized in 
> >this
> >function
> >
> > 
> >
> I apologise if this is obvious / stupid, but is this really a bug in the 
> class, or in the error message?
> I get the same error arriving from:
> #include<vector>
> struct ptrwrapper {
> int* a;
> ptrwrapper() {}
> };
> std::vector<ptrwrapper> v(1);
> Which is surely correct code? I imagine what is happening is that the 
> pointer is being copied, however there is (I think?) nothing wrong with 
> copying an unassigned pointer,

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

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]