libstdc++/6886: bit vector iterator uses wrong 1 constant
meissner@suse.de
meissner@suse.de
Fri May 31 05:16:00 GMT 2002
>Number: 6886
>Category: libstdc++
>Synopsis: bit vector iterator uses wrong 1 constant
>Confidential: no
>Severity: critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri May 31 05:16:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Marcus Meissner <meissner@suse.de>
>Release: 3.1 20020410 (prerelease)
>Organization:
SuSE Linux AG
>Environment:
System: Linux gershwin 2.4.18-SMP #1 SMP Mon May 13 09:48:57 UTC 2002 x86_64 unknown
Architecture: x86_64
host: x86_64-unknown-linux-gnu
build: x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-gnu
configured with: /home/hammer/gcc/configure --prefix=/usr --host=x86_64-unknown-linux --build=x86_64-unknown-linux --libdir=/usr/lib64 --enable-languages=c,c++ --enable-threads=posix --disable-nls
>Description:
The stl bitvector implementation contains in both the iterator and
const_iterator implementation the code:
reference operator*() const { return reference(_M_p, 1U << _M_offset); }
Since the bit_type is an unsigned long, it should be 1UL here.
I have attached a testcase exhibiting the problem and a fix in
the Fix section.
Ciao, Marcus
>How-To-Repeat:
#include <assert.h>
#include <vector>
typedef std::vector<bool> bvec;
int
main() {
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++;
}
assert (num == 4);
return 0;
}
>Fix:
--- libstdc++-v3/include/bits/stl_bvector.h.long Fri May 31 11:35:24 2002
+++ libstdc++-v3/include/bits/stl_bvector.h Fri May 31 11:35:36 2002
@@ -166,7 +166,7 @@
_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 @@
: _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();
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list