Closed edubart closed 3 years ago
Thank you for the bug report. I noticed the first one, but that error looks weird. I believe gcc infers the range of possible values cap
can take and conclude that the range is [18446744071562067968, 18446744073709551615], but that inference is simply wrong. cap
is much smaller value. Is this a gcc bug, or did I miss something?
For the second switch, I should add -Wno-switch
to Makefile. I'll do that.
Turned out that I already added -Wno-switch
in 4a9378dc78645a397ff2cab68fc4e72666c6c64a.
Changing cap
to unsigned int makes the first warning go away.
But do you know why that fixes the problem? That variable shouldn't indeed have a negative value, but the value can't be negative anyway, so the inference of gcc looks weird.
I investigated this problem a little bit more, and now I believe that, if gcc doesn't have enough information on the exact value range, gcc makes a pessimistic assumption on what value a variable can take and issue a warning based on an incorrect assumption. I'll fix that by adding an assert()
to constrain the value range.
When I compile with O2 I have this warning on GCC 10.2.0:
And with Clang many warnings about switches, like: