I think GCC is wrongfully producing a [-Wshift-negative-value] warning.
I have a function that should produce a suffix mask of a certain length provided by its single input argument:
#include <stdint.h>
uint16_t get_suffix_mask_sht(uint8_t shift) {
return (~(~((uint16_t) 0) << shift));
}
I have tried to compile this function with the following compiler options on different versions of gcc
-Werror -Wextra
This warning also occurs if I change the output from uint16_t
to uint8_t
. Bigger output types, i.e. uint32_t
don't produce this warning.
I am using an older version of GCC: 7.4. But I have tried this out on godbolt using the latest GCC 9.x versions and they all produce the same warning. Clang versions however do not produce this error.