From: Paul Eggert Date: Mon, 11 May 2026 06:29:05 +0000 (-0700) Subject: maint: pacify GCC 16 -Wuseless-cast X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=834ea48535b16c64db414f3b610ae4a2ae98c6e8;p=thirdparty%2Fcoreutils.git maint: pacify GCC 16 -Wuseless-cast This mostly either removes casts if they are always no-ops, or replaces casts (TYPE)(EXPR) with compound literals (TYPE){EXPR}. Compound literals are a bit safer anyway, as casts are too powerful in C. * src/cksum_avx2.c (cksum_avx2): * src/cksum_avx512.c (cksum_avx512): * src/cksum_crc.c (cksum_slice8): * src/cksum_pclmul.c (cksum_pclmul): * src/cp-hash.c (remember_copied): * src/numfmt.c (simple_strtod_float): * src/system.h (x_timestyle_match): Omit no-op casts. * src/cp-hash.c (src_to_dest_hash): * src/dd.c (dd_copy): * src/df.c (devlist_hash): * src/env.c (splitbuf_append_byte): * src/getlimits.c (print_int, main): * src/ls.c (dev_ino_hash): * src/truncate.c (do_ftruncate): Replace casts with compound literals. * src/factor.c: Ignore -Wuseless-cast, as we include the imported longlong.h file, which has many of them. * src/numfmt.c (powerld): 2nd arg is now ptrdiff_t, not int, so that integers are not silently mishandled in outlandish cases. --- diff --git a/src/cksum_avx2.c b/src/cksum_avx2.c index fe157b508b..eea8e073aa 100644 --- a/src/cksum_avx2.c +++ b/src/cksum_avx2.c @@ -74,7 +74,7 @@ cksum_avx2 (FILE *fp, uint_fast32_t *crc_out, intmax_t *length_out) return false; } - datap = (__m256i *)buf; + datap = buf; /* Fold in parallel 16x 16-byte blocks into 8x 16-byte blocks */ if (bytes_read >= 16 * 8 * 2) diff --git a/src/cksum_avx512.c b/src/cksum_avx512.c index 9ac06c63f1..cc13023215 100644 --- a/src/cksum_avx512.c +++ b/src/cksum_avx512.c @@ -81,7 +81,7 @@ cksum_avx512 (FILE *fp, uint_fast32_t *crc_out, intmax_t *length_out) return false; } - datap = (__m512i *)buf; + datap = buf; /* Fold in parallel 32x 16-byte blocks into 16x 16-byte blocks */ if (bytes_read >= 16 * 8 * 4) diff --git a/src/cksum_crc.c b/src/cksum_crc.c index de93c1bf55..dbe2b994f9 100644 --- a/src/cksum_crc.c +++ b/src/cksum_crc.c @@ -244,7 +244,7 @@ cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, intmax_t *length_out) } /* Process multiples of 8 bytes */ - datap = (uint32_t *)buf; + datap = buf; while (bytes_read >= 8) { uint32_t first = *datap++, second = *datap++; diff --git a/src/cksum_pclmul.c b/src/cksum_pclmul.c index f8860c19ba..a3a83b2829 100644 --- a/src/cksum_pclmul.c +++ b/src/cksum_pclmul.c @@ -72,7 +72,7 @@ cksum_pclmul (FILE *fp, uint_fast32_t *crc_out, intmax_t *length_out) return false; } - datap = (__m128i *)buf; + datap = buf; /* Fold in parallel eight 16-byte blocks into four 16-byte blocks */ if (bytes_read >= 16 * 8) diff --git a/src/cp-hash.c b/src/cp-hash.c index 1d5159838a..80d4b00b4e 100644 --- a/src/cp-hash.c +++ b/src/cp-hash.c @@ -55,7 +55,7 @@ src_to_dest_hash (void const *x, size_t table_size) /* Ignoring the device number here should be fine. */ /* The cast to uintmax_t prevents negative remainders if st_ino is negative. */ - return (uintmax_t) p->st_ino % table_size; + return (uintmax_t) {p->st_ino} % table_size; } /* Compare two Src_to_dest entries. @@ -135,7 +135,7 @@ remember_copied (char const *name, ino_t ino, dev_t dev) if (ent_from_table != ent) { src_to_dest_free (ent); - return (char *) ent_from_table->name; + return ent_from_table->name; } /* New key; insertion succeeded. */ diff --git a/src/dd.c b/src/dd.c index 72dcef1683..26382a233b 100644 --- a/src/dd.c +++ b/src/dd.c @@ -2376,7 +2376,7 @@ dd_copy (void) { diagnose (errno, _("failed to truncate to %jd bytes" " in output file %s"), - (intmax_t) output_offset, quoteaf (output_file)); + (intmax_t) {output_offset}, quoteaf (output_file)); return EXIT_FAILURE; } } diff --git a/src/df.c b/src/df.c index f41ba3a870..b3d83f505a 100644 --- a/src/df.c +++ b/src/df.c @@ -667,7 +667,7 @@ static size_t devlist_hash (void const *x, size_t table_size) { struct devlist const *p = x; - return (uintmax_t) p->dev_num % table_size; + return (uintmax_t) {p->dev_num} % table_size; } static bool diff --git a/src/env.c b/src/env.c index 583f7e12b3..3e4f9b3fca 100644 --- a/src/env.c +++ b/src/env.c @@ -304,7 +304,7 @@ splitbuf_append_byte (struct splitbuf *ss, char c) if (ss->half_alloc * sizeof *ss->argv <= string_bytes) splitbuf_grow (ss); ((char *) (ss->argv + ss->half_alloc))[string_bytes] = c; - ss->argv[ss->argc] = (char *) (intptr_t) (string_bytes + 1); + ss->argv[ss->argc] = (char *) (intptr_t) {string_bytes + 1}; } /* If SS's most recent character was a separator, finish off its diff --git a/src/factor.c b/src/factor.c index 06f7b31a23..e9c3732072 100644 --- a/src/factor.c +++ b/src/factor.c @@ -175,6 +175,11 @@ typedef uint64_t UDItype; # if defined ASSERT || defined __GMP_DECLSPEC || defined __GMP_GNUC_PREREQ # endif +/* longlong.h uses casts even when useless. */ +# if 14 <= __GNUC__ +# pragma GCC diagnostic ignored "-Wuseless-cast" +# endif + # if _ARCH_PPC # define HAVE_HOST_CPU_FAMILY_powerpc 1 # endif diff --git a/src/getlimits.c b/src/getlimits.c index 86224a3d0b..514dd3c09e 100644 --- a/src/getlimits.c +++ b/src/getlimits.c @@ -159,12 +159,12 @@ main (int argc, char **argv) (char const *) NULL); #define print_int(TYPE) \ - sprintf (limit + 1, "%ju", (uintmax_t) TYPE##_MAX); \ + sprintf (limit + 1, "%ju", (uintmax_t) {TYPE##_MAX}); \ printf (#TYPE"_MAX=%s\n", limit + 1); \ printf (#TYPE"_OFLOW=%s\n", decimal_absval_add_one (limit)); \ if (TYPE##_MIN) \ { \ - sprintf (limit + 1, "%jd", (intmax_t) TYPE##_MIN); \ + sprintf (limit + 1, "%jd", (intmax_t) {TYPE##_MIN}); \ printf (#TYPE"_MIN=%s\n", limit + 1); \ printf (#TYPE"_UFLOW=%s\n", decimal_absval_add_one (limit)); \ } @@ -199,9 +199,9 @@ main (int argc, char **argv) print_float (LDBL); /* Other useful constants */ - printf ("SIGRTMIN=%jd\n", (intmax_t) SIGRTMIN); - printf ("SIGRTMAX=%jd\n", (intmax_t) SIGRTMAX); - printf ("IO_BUFSIZE=%ju\n", (uintmax_t) IO_BUFSIZE); + printf ("SIGRTMIN=%jd\n", (intmax_t) {SIGRTMIN}); + printf ("SIGRTMAX=%jd\n", (intmax_t) {SIGRTMAX}); + printf ("IO_BUFSIZE=%ju\n", (uintmax_t) {IO_BUFSIZE}); /* Errnos */ errno_iterate (print_errno, NULL); diff --git a/src/ls.c b/src/ls.c index 394e7d2670..3d583b85f1 100644 --- a/src/ls.c +++ b/src/ls.c @@ -1425,7 +1425,7 @@ static size_t dev_ino_hash (void const *x, size_t table_size) { struct dev_ino const *p = x; - return (uintmax_t) p->st_ino % table_size; + return (uintmax_t) {p->st_ino} % table_size; } static bool diff --git a/src/numfmt.c b/src/numfmt.c index b4d6d47770..467e5d79be 100644 --- a/src/numfmt.c +++ b/src/numfmt.c @@ -330,7 +330,7 @@ suffix_power_char (int power) /* Similar to 'powl(3)' but without requiring 'libm'. */ static long double -powerld (long double base, int x) +powerld (long double base, ptrdiff_t x) { long double result = base; if (x == 0) @@ -588,9 +588,9 @@ simple_strtod_float (char const *input_str, return SSE_INVALID_NUMBER; /* number of digits in the fractions. */ - size_t exponent = ptr2 - *endptr; + ptrdiff_t exponent = ptr2 - *endptr; - val_frac = ((long double) val_frac) / powerld (10, exponent); + val_frac /= powerld (10, exponent); /* TODO: detect loss of precision (only really 18 digits of precision across all digits (before and after '.')). */ diff --git a/src/system.h b/src/system.h index 545377335f..d0f2e0c44d 100644 --- a/src/system.h +++ b/src/system.h @@ -1007,7 +1007,7 @@ x_timestyle_match (char const * style, bool allow_posix, int fail_status) { ptrdiff_t res = argmatch (style, timestyle_args, - (char const *) timestyle_types, + timestyle_types, timestyle_types_size); if (res < 0) { diff --git a/src/truncate.c b/src/truncate.c index 77133382ef..7119132e06 100644 --- a/src/truncate.c +++ b/src/truncate.c @@ -190,7 +190,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize, if (ftruncate (fd, nsize) != 0) { error (0, errno, _("failed to truncate %s at %jd bytes"), - quoteaf (fname), (intmax_t) nsize); + quoteaf (fname), (intmax_t) {nsize}); return false; }