C++ Logo


Advanced search

Subject: bitset, the copy assignment operator: a bug in the description (C++ 20)
From: Vladimir Grigoriev (vlad.moscow_at_[hidden])
Date: 2019-09-27 11:55:43

In the description of the copy assignment operator of the standard class std::bitset there are used a wrong logic. Members

bitset& operator&=(const bitset& rhs) noexcept;

1 Effects: Clears each bit in *this for which the corresponding bit in rhs is clear, and leaves all other bits unchanged .

However gcc behaves differently. Consider the following demonstrative program.

#include <iostream>
#include <bitset>
int main()
std::bitset<3> b1( "101" );
std::bitset<3> b2( "010" );

std::cout << "b1 = " << b1 << '\n';
std::cout << "b2 = " << b2 << '\n';

b1 = b2;

std::cout << "b1 = " << b1 << '\n';
Its output is

b1 = 101
b2 = 010
b1 = 010
So the second bit was changed though the corresponding bit in b2 is not clear.

With best regards,
Vlad from Moscow
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com

STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups