* lib/fsusage.c (PROPAGATE_ALL_ONES):
* lib/fts-cycle.c (AD_hash):
* lib/hash.c (hash_print_statistics, hash_print):
* lib/malloca.h (nmalloca):
* lib/readutmp.c (add_utmp):
* lib/xsize.h (xtimes):
When ((t) (E)) might provoke a -Wuseless-cast diagnostic in GCC 16,
use ((t) {E}) when that’s easy, i.e., when the expression is not
intended for use as a constant expression.
---
 ChangeLog       | 10 ++++++++++
 lib/fsusage.c   |  2 +-
 lib/fts-cycle.c |  2 +-
 lib/hash.c      | 12 +++++++-----
 lib/malloca.h   |  2 +-
 lib/readutmp.c  |  8 ++++----
 6 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 404cacf100..7f19a8509e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2026-05-07  Paul Eggert  <[email protected]>
 
+       maint: pacify -Wuseless-cast via compound literals
+       * lib/fsusage.c (PROPAGATE_ALL_ONES):
+       * lib/fts-cycle.c (AD_hash):
+       * lib/hash.c (hash_print_statistics, hash_print):
+       * lib/malloca.h (nmalloca):
+       * lib/readutmp.c (add_utmp):
+       When ((t) (E)) might provoke a -Wuseless-cast diagnostic in GCC 16,
+       use ((t) {E}) when that’s easy, i.e., when the expression is not
+       intended for use as a constant expression.
+
        fpucw: pacify -Wuseless-cast
        * lib/fpucw.h (SET_FPUCW, BEGIN_LONG_DOUBLE_ROUNDING): Pacify gcc
        16 -Wuseless-cast by avoiding casts of void expressions to void.
diff --git a/lib/fsusage.c b/lib/fsusage.c
index 1700a19c99..7c8c34f574 100644
--- a/lib/fsusage.c
+++ b/lib/fsusage.c
@@ -57,7 +57,7 @@
     && (~ (x) == (sizeof (x) < sizeof (int) \
                   ? - (1 << (sizeof (x) * CHAR_BIT)) \
                   : 0))) \
-   ? UINTMAX_MAX : (uintmax_t) (x))
+   ? UINTMAX_MAX : (uintmax_t) {x})
 
 /* Extract the top bit of X as an uintmax_t value.  */
 #define EXTRACT_TOP_BIT(x) ((x) \
diff --git a/lib/fts-cycle.c b/lib/fts-cycle.c
index f925e81a16..c7cdd28df8 100644
--- a/lib/fts-cycle.c
+++ b/lib/fts-cycle.c
@@ -41,7 +41,7 @@ static size_t
 AD_hash (void const *x, size_t table_size)
 {
   struct Active_dir const *ax = x;
-  return (uintmax_t) ax->ino % table_size;
+  return (uintmax_t) {ax->ino} % table_size;
 }
 
 /* Set up the cycle-detection machinery.  */
diff --git a/lib/hash.c b/lib/hash.c
index d428a26a19..d1012f0afc 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -224,13 +224,15 @@ hash_print_statistics (const Hash_table *table, FILE 
*stream)
   size_t n_buckets_used = hash_get_n_buckets_used (table);
   size_t max_bucket_length = hash_get_max_bucket_length (table);
 
-  fprintf (stream, "# entries:         %lu\n", (unsigned long int) n_entries);
-  fprintf (stream, "# buckets:         %lu\n", (unsigned long int) n_buckets);
+  fprintf (stream, "# entries:         %lu\n",
+           (unsigned long int) {n_entries});
+  fprintf (stream, "# buckets:         %lu\n",
+           (unsigned long int) {n_buckets});
   fprintf (stream, "# buckets used:    %lu (%.2f%%)\n",
-           (unsigned long int) n_buckets_used,
+           (unsigned long int) {n_buckets_used},
            (100.0 * n_buckets_used) / n_buckets);
   fprintf (stream, "max bucket length: %lu\n",
-           (unsigned long int) max_bucket_length);
+           (unsigned long int) {max_bucket_length});
 }
 
 /* Hash KEY and return a pointer to the selected bucket.
@@ -1016,7 +1018,7 @@ hash_print (const Hash_table *table)
        bucket++)
     {
       if (bucket)
-        printf ("%lu:\n", (unsigned long int) (bucket - table->bucket));
+        printf ("%lu:\n", (unsigned long int) {bucket - table->bucket});
 
       for (struct hash_entry *cursor = bucket; cursor; cursor = cursor->next)
         {
diff --git a/lib/malloca.h b/lib/malloca.h
index 1ebe691615..5fb955e5f7 100644
--- a/lib/malloca.h
+++ b/lib/malloca.h
@@ -102,7 +102,7 @@ extern void *mmalloca (size_t n)
    on the stack.  N and S should be nonnegative and free of side effects.
    The array must be freed using freea() before the function returns.  */
 #define nmalloca(n, s) \
-  (xalloc_oversized (n, s) ? NULL : malloca ((n) * (size_t) (s)))
+  (xalloc_oversized (n, s) ? NULL : malloca ((n) * (size_t) {s}))
 
 
 #ifdef __cplusplus
diff --git a/lib/readutmp.c b/lib/readutmp.c
index 7320c4cbed..6e43b5e956 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -269,10 +269,10 @@ add_utmp (struct utmp_alloc a, int options,
          relative to the end of the allocated storage, so that these
          slots survive realloc.  The slots will be relocated back just
          before read_utmp returns.  */
-      ut->ut_user = (char *) (intptr_t) (ut->ut_user - stringlim);
-      ut->ut_id   = (char *) (intptr_t) (ut->ut_id   - stringlim);
-      ut->ut_line = (char *) (intptr_t) (ut->ut_line - stringlim);
-      ut->ut_host = (char *) (intptr_t) (ut->ut_host - stringlim);
+      ut->ut_user = (char *) (intptr_t) {ut->ut_user - stringlim};
+      ut->ut_id   = (char *) (intptr_t) {ut->ut_id   - stringlim};
+      ut->ut_line = (char *) (intptr_t) {ut->ut_line - stringlim};
+      ut->ut_host = (char *) (intptr_t) {ut->ut_host - stringlim};
       a.filled++;
       a.string_bytes += needed_string_bytes;
     }
-- 
2.54.0


Reply via email to