mercredi 4 juillet 2018

Is shifting std::bitset

As discussed in Is right shift undefined behavior if the count is larger than the width of the type?, shifting a value is undefined if the number of bit shifts exceeds the effective operand size.

Thus, in the following, the value of bar is undefined:

uint32_t foo = 123;
uint32_t bar = (foo >> 33);

Are such shift operations well defined for std::bitset? As in:

std::bitset<32> foo(123);
std::bitset<32> (bar >> 33);

And in which official document can I find such information?

The case is not explicitly stated on cppreference (https://en.cppreference.com/w/cpp/utility/bitset/operator_ltltgtgt).

Aucun commentaire:

Enregistrer un commentaire