[PATCH] Fix PR libstdc++/19510: Uninitialized variable in some iterators
Chris Jefferson
caj@cs.york.ac.uk
Thu Jan 20 11:34:00 GMT 2005
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, 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.
Chris
>Apart from the strange variable name 'SR.133' (which is a different issue)
>the warning seems to be justified as the default constructor of
>_List_iterator does not initialize the pointer _M_node.
>_List_const_iterator, _Rb_tree_iterator, and _Rb_tree_const_iterator
>have the same problem.
>
>The following patch fixes that by adding the appropriate initializations.
>Due to changed line numbers the testsuite needs some trivial tweaks.
>
>Bootstrapped and regtested on i686-pc-linux-gnu.
>OK to apply to mainline?
>
>Btw, the initialization is missing in 3.4, too. But the warning is not
>triggered. Should the patch be applied there, too?
>
>Regards,
>Volker
>
>
>2005-01-20 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
>
> PR libstdc++/19510
> * include/bits/stl_list.h (_List_iterator): Initialize _M_node
> in constructor.
> (_List_const_iterator): Likewise.
> * include/bits/stl_tree.h (_Rb_tree_iterator): Likewise.
> (_Rb_tree_const_iterator): Likewise.
>
> * testsuite/23_containers/map/operators/1_neg.cc: Adjust line numbers.
> * testsuite/23_containers/set/operators/1_neg.cc: Likewise.
>
>
>===================================================================
>--- gcc/libstdc++-v3/include/bits/stl_list.h 19 Nov 2004 12:44:09 -0000 1.45
>+++ gcc/libstdc++-v3/include/bits/stl_list.h 18 Jan 2005 18:49:06 -0000
>@@ -119,7 +119,8 @@ namespace _GLIBCXX_STD
> typedef _Tp* pointer;
> typedef _Tp& reference;
>
>- _List_iterator() { }
>+ _List_iterator()
>+ : _M_node() { }
>
> _List_iterator(_List_node_base* __x)
> : _M_node(__x) { }
>@@ -195,7 +196,8 @@ namespace _GLIBCXX_STD
> typedef const _Tp* pointer;
> typedef const _Tp& reference;
>
>- _List_const_iterator() { }
>+ _List_const_iterator()
>+ : _M_node() { }
>
> _List_const_iterator(const _List_node_base* __x)
> : _M_node(__x) { }
>====================================================================
>--- gcc/libstdc++-v3/include/bits/stl_tree.h 13 Oct 2004 00:11:13 -0000 1.40
>+++ gcc/libstdc++-v3/include/bits/stl_tree.h 18 Jan 2005 21:48:51 -0000
>@@ -161,7 +161,8 @@ namespace std
> typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
> typedef _Rb_tree_node<_Tp>* _Link_type;
>
>- _Rb_tree_iterator() { }
>+ _Rb_tree_iterator()
>+ : _M_node() { }
>
> _Rb_tree_iterator(_Link_type __x)
> : _M_node(__x) { }
>@@ -231,7 +232,8 @@ namespace std
> typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
> typedef const _Rb_tree_node<_Tp>* _Link_type;
>
>- _Rb_tree_const_iterator() { }
>+ _Rb_tree_const_iterator()
>+ : _M_node() { }
>
> _Rb_tree_const_iterator(_Link_type __x)
> : _M_node(__x) { }
>===================================================================
>--- gcc/libstdc++-v3/testsuite/23_containers/map/operators/1_neg.cc 23 Sep 2004 21:27:25 -0000 1.5
>+++ gcc/libstdc++-v3/testsuite/23_containers/map/operators/1_neg.cc 19 Jan 2005 22:10:53 -0000
>@@ -41,5 +41,5 @@ void test01()
> test &= itr == mapByName.end(); // { dg-error "no" }
> }
>
>-// { dg-error "candidates are" "" { target *-*-* } 208 }
>-// { dg-error "candidates are" "" { target *-*-* } 212 }
>+// { dg-error "candidates are" "" { target *-*-* } 209 }
>+// { dg-error "candidates are" "" { target *-*-* } 213 }
>===================================================================
>--- gcc/libstdc++-v3/testsuite/23_containers/set/operators/1_neg.cc 23 Sep 2004 21:27:25 -0000 1.5
>+++ gcc/libstdc++-v3/testsuite/23_containers/set/operators/1_neg.cc 19 Jan 2005 22:13:26 -0000
>@@ -39,5 +39,5 @@ void test01()
> test &= itr == setByName.end(); // { dg-error "no" }
> }
>
>-// { dg-error "candidates are" "" { target *-*-* } 281 }
>-// { dg-error "candidates are" "" { target *-*-* } 285 }
>+// { dg-error "candidates are" "" { target *-*-* } 283 }
>+// { dg-error "candidates are" "" { target *-*-* } 287 }
>===================================================================
>
>
>
>
More information about the Libstdc++
mailing list