From 4d341738164df7bab6cc41d38859205eb9e27a12 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 4 Jul 2026 18:27:49 -0700
Subject: [PROPOSED] =?UTF-8?q?Document=20why=20zic.c=20uses=20unary=20?=
 =?UTF-8?q?=E2=80=98+=E2=80=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* private.h (INT_PROMOTE): New macro.
* zic.c (MAX_FIELDS): Use it.
---
 private.h | 5 +++++
 zic.c     | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/private.h b/private.h
index b0faaeb9..7918082d 100644
--- a/private.h
+++ b/private.h
@@ -954,6 +954,11 @@ ATTRIBUTE_POSIX2TIME time_t time2posix_z(timezone_t, time_t);
 #define TYPE_SIGNED(type) (((type) -1) < 0)
 #define TWOS_COMPLEMENT(type) (TYPE_SIGNED (type) && (! ~ (type) -1))
 
+/* Yield the value of the arithmetic expression X after integer promotion.
+   This is safer than a cast, which in general would accept even
+   pointers and which might trap or yield a value not equal to X.  */
+#define INT_PROMOTE(x) (+(x))
+
 /* Minimum and maximum of two values.  Use lower case to avoid
    naming clashes with standard include files.  */
 #define max(a, b) ((a) > (b) ? (a) : (b))
diff --git a/zic.c b/zic.c
index af2bb80a..a2c2dec8 100644
--- a/zic.c
+++ b/zic.c
@@ -412,10 +412,10 @@ enum {
 };
 
 /* The maximum number of fields on any of the above lines.
-   (The "+"s pacify gcc -Wenum-compare.)  */
+   (This uses INT_PROMOTE to pacify gcc -Wenum-compare.)  */
 enum {
-  MAX_FIELDS = max(max(+RULE_FIELDS, +LINK_FIELDS),
-		   max(+LEAP_FIELDS, +EXPIRES_FIELDS))
+  MAX_FIELDS = max(max(INT_PROMOTE(RULE_FIELDS), INT_PROMOTE(LINK_FIELDS)),
+		   max(INT_PROMOTE(LEAP_FIELDS), INT_PROMOTE(EXPIRES_FIELDS)))
 };
 
 /*
-- 
2.53.0

