I'm getting a spurious "warning: left shift count >= width of type" when compiling some template code with gcc:
template <int N> class bitval {
unsigned long val;
#pragma GCC diagnostic ignored "-Wall"
const bitval &check() {
if (N < sizeof(unsigned long) * CHAR_BIT && val >= (1UL << N)) {
std::clog << val << " out of range for " << N << " bits in " << std::endl;
val &= (1UL << N) - 1; }
return *this; }
#pragma GCC diagnostic pop
};
The problem being that when it is instantiated with N == 64, it gives the warning.
Now the warning is completely spurious, as the code checks for N being large enough that no check/mask is needed, so when N is 64, the shifts will never happen. But gcc warns anyways. So I'm trying to disable the warning, but I can't figure out the needed #pragma magic to shut it up...