Suppress compiler warnings in new pgstats code.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 27 Feb 2023 22:21:31 +0000 (17:21 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 27 Feb 2023 22:21:31 +0000 (17:21 -0500)
commit728560db7d868b3ded9a8675742083ab89bcff7c
tree8ef600b8d46773eddddfb0c2f90782b3d6c00803
parent53fe7e6cb81b26218f8652f5f3fe4fece944f958
Suppress compiler warnings in new pgstats code.

Some clang versions whine about comparing an enum variable to
a value outside the range of the enum, on the grounds that the
result must be constant.  In the cases we fix here, the loops
will terminate only if the enum variable can in fact hold a
value one beyond its declared range.  While that's very likely
to always be true for these enum types, it still seems like a
poor coding practice to assume it; so use "int" loop variables
instead to silence the warnings.  (This matches what we've done
in other places, for example loops over the range of ForkNumber.)

While at it, let's drop the XXX_FIRST macros for these enums and just
write zeroes for the loop start values.  The apparent flexibility
seems rather illusory given that iterating up to one-less-than-
the-number-of-values is only correct for a zero-based range.

Melanie Plageman

Discussion: https://postgr.es/m/20520.1677435600@sss.pgh.pa.us
src/backend/utils/activity/pgstat_io.c
src/backend/utils/adt/pgstatfuncs.c
src/include/pgstat.h