This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Bug in bitset
- From: Tomasz Czajka <tczajka at duch dot mimuw dot edu dot pl>
- To: Nathan Myers <ncm-nospam at cantrip dot org>
- Cc: <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 20 Nov 2001 13:32:55 +0100 (CET)
- Subject: Re: Bug in bitset
Try this:
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<70> bs;
bs.set(0);
bs <<= 32;
for (int i = 69; i >= 0; --i)
cout << bs[i];
cout << '\n';
}
Result:
0000010000000000000000000000000000000100000000000000000000000000000000
I have gcc version 2.95.3, but I think there's the same bug in some later
versions.
In a "shift left" function in bitset, when they shift by x bits,
they do "<<=(x%32)" and ">>=(32-x%32)" for each word, the second is
incorrect for x==32, because you can only shift by 0..31 bits.
Tomek