Open iacore opened 1 year ago
In https://en.cppreference.com/w/cpp/language/operator_arithmetic, section "Bitwise shift operators"
In any case, if the value of the right operand is negative or is greater or equal to the number of bits in the promoted left operand, the behavior is undefined.
I handled the specific UB case.
0 is not negative. I'll modify the assertion to be "width >= 0 && width < sizeof(int64_t)".
when width is 0, ((sizeof(num) - width) * 8) is 64, which is UB
width
((sizeof(num) - width) * 8)
Good point. Then, I'll put assert(width > 0).
In https://en.cppreference.com/w/cpp/language/operator_arithmetic, section "Bitwise shift operators"
I handled the specific UB case.