This is the mail archive of the gcc-patches@gcc.gnu.org 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]

[libstdc++, 3.1] fix libstdc++/6886


The submitter of the PR helpfully included a testcase and patch.  It doesn't
cause any regressions on 32-bit targets like i686-pc-linux-gnu (how could
it have), fixes a problem the submitter sees on a 64-bit target, and is
just good programming practice besides.

Trunk and branch.


2002-05-31  Marcus Meissner  <meissner@suse.de>

	* include/bits/stl_bvector.h:  Use UL suffix for unsigned longs.
	* testsuite/23_containers/vector_bool.cc (test02):  New test.


Index: include/bits/stl_bvector.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_bvector.h,v
retrieving revision 1.14
diff -u -3 -p -r1.14 stl_bvector.h
--- include/bits/stl_bvector.h	12 Mar 2002 01:43:44 -0000	1.14
+++ include/bits/stl_bvector.h	1 Jun 2002 00:44:50 -0000
@@ -166,7 +166,7 @@ struct _Bit_iterator : public _Bit_itera
   _Bit_iterator(_Bit_type * __x, unsigned int __y) 
     : _Bit_iterator_base(__x, __y) {}
 
-  reference operator*() const { return reference(_M_p, 1U << _M_offset); }
+  reference operator*() const { return reference(_M_p, 1UL << _M_offset); }
   iterator& operator++() {
     _M_bump_up();
     return *this;
@@ -223,7 +223,7 @@ struct _Bit_const_iterator : public _Bit
     : _Bit_iterator_base(__x._M_p, __x._M_offset) {}
 
   const_reference operator*() const {
-    return _Bit_reference(_M_p, 1U << _M_offset);
+    return _Bit_reference(_M_p, 1UL << _M_offset);
   }
   const_iterator& operator++() {
     _M_bump_up();
Index: testsuite/23_containers/vector_bool.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/23_containers/vector_bool.cc,v
retrieving revision 1.1
diff -u -3 -p -r1.1 vector_bool.cc
--- testsuite/23_containers/vector_bool.cc	7 Mar 2002 06:53:23 -0000	1.1
+++ testsuite/23_containers/vector_bool.cc	1 Jun 2002 00:44:50 -0000
@@ -29,8 +29,32 @@ void test01()
   ++i;
 }
 
+// libstdc++/6886
+void test02()
+{
+  typedef std::vector<bool>  bvec;
+  int  i, num = 0;
+  bvec v;
+
+  v.resize(66);
+
+  for (i = 0 ; i < 66 ; ++i)
+    v[i] = 0;
+
+  v[1]    = 1;
+  v[33]   = 1;
+  v[49]   = 1;
+  v[65]   = 1;
+
+  for (bvec::iterator j = v.begin() ; j != v.end() ; j++)
+    if (bool(*j)) ++num;
+
+  VERIFY( num == 4 );
+}
+
 int main()
 {
   test01();
+  test02();
   return 0;
 }


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