https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83407

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonny Grant from comment #2)
> Hello Richard
> 
> Static analysis could spot this example case?

But there's nothing wrong with your example. It creates the maximum value of
type size_t and prints it ... that's perfectly valid.

> Is there a legitimate case?

Yes, of course there are legitimate use cases for a fundamental property of
unsigned types that is how they've worked for decades.

Off the top of my head, various bitwise manipulations for rounding values up or
down to the next power-of-two, e.g. for finding correct alignment, rely on the
fact that unsigned integers wrap instead of overflowing.

If you don't want modulo arithmetic, don't use unsigned types. Using signed
types for indices means you get the usual arithmetic rules and can check for
values less than zero, instead of getting huge positive values.

Reply via email to