On 2025-12-19 09:12, Christos Zoulas via tz wrote:
Gcc with -Wall -Wextra -Wtype-limits produces warnings with:

#define TYPE_SIGNED(T)  ((T)-1) < 0)

error: comparison of unsigned expression in '< 0' is always false 
[-Werror=type-limits]

Perhaps use something that checks the sign bit directly?

#define TYPE_SIGNED(T) \
     (((T)~(T)0 >> (sizeof(T) * CHAR_BIT - 1)) == (T)-1)

Let’s not, as the C standard does not require the more-complicated expression to check the sign bit (e.g., there could be padding bits), whereas it does require tzcode’s simpler expression to work (even on floating-point types).

More generally, GCC’s -Wtype-limits is not a good option for portable code, since it’s too common for that flag to misfire on code intended to work regardless of whether types like time_t are signed. This is why the GCC_DEBUG_FLAGS in tzcode’s Makefile specifies -Wno-type-limits. There are similar issues with GCC’s -Wformat-nonliteral and -Wsign-compare.

To check the code I suggest tzcode’s GCC_DEBUG_FLAGS, or if that’s too drastic I suggest appending -Wno-format-nonliteral -Wno-sign-compare -Wno-type-limits, as GCC_DEBUG_FLAGS does.

PS. On my long list of things to do was to merge the changes between
tzcode and NetBSD, so that tzcode’s localtime.c could be used unchanged in NetBSD. It sounds like you’ve started the ball rolling on that; if I can be of any help please let me know.

Reply via email to