Bug in bitset

Tomasz Czajka tczajka@duch.mimuw.edu.pl
Mon Nov 5 17:12:00 GMT 2001


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




More information about the Libstdc++ mailing list