From: Paul Eggert Date: Fri, 8 May 2026 19:12:07 +0000 (-0700) Subject: Pacify -Wuseless-cast via compound literals in lib X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e6f301b8efe5b0cf7721ed16cf8a7828bc1119a;p=thirdparty%2Fgnulib.git Pacify -Wuseless-cast via compound literals in lib * lib/bitset.c (bitset_print): * lib/bitset/list.c (LBITSET_ELT_BITS, debug_lbitset): * lib/bitset/table.c (TBITSET_ELT_BITS): * lib/bitsetv.c (bitsetv_dump, debug_bitsetv) (bitsetv_matrix_dump): * lib/gettext.h (gettext, ngettext, textdomain, bindtextdomain) (bind_textdomain_codeset): * lib/gl_anyavltree_list2.h (gl_tree_nx_add_first) (gl_tree_nx_add_last, gl_tree_nx_add_before) (gl_tree_nx_add_after): * lib/gl_anylinked_list2.h (gl_linked_nx_create) (gl_linked_node_nx_set_value, gl_linked_nx_set_at) (gl_linked_search_from_to, gl_linked_indexof_from_to) (gl_linked_nx_add_first, gl_linked_nx_add_last) (gl_linked_nx_add_before, gl_linked_nx_add_after) (gl_linked_nx_add_at): * lib/gl_anyrbtree_list2.h (gl_tree_nx_add_first) (gl_tree_nx_add_last, gl_tree_nx_add_before) (gl_tree_nx_add_after): * lib/gl_anytree_list2.h (gl_tree_node_nx_set_value) (gl_tree_nx_set_at): * lib/gl_anytreehash_list1.h (add_nodes_to_buckets): * lib/gl_anytreehash_list2.h (gl_tree_search_from_to): * lib/gl_array_list.c, lib/gl_carray_list.c, lib/gl_sublist.c: (INDEX_TO_NODE): * lib/gl_hash_map.c (gl_hash_search, gl_hash_nx_getput) (gl_hash_getremove): * lib/gl_hash_set.c (gl_hash_search, gl_hash_nx_add) (gl_hash_remove): * lib/gl_linkedhash_map.c (gl_linkedhash_search) (gl_linkedhash_nx_getput, gl_linkedhash_getremove): * lib/gl_linkedhash_set.c (gl_linkedhash_search) (gl_linkedhash_nx_add, gl_linkedhash_remove): * lib/isnand-nolibm.h (isnand): * lib/isnanf-nolibm.h (isnanf): * lib/isnanl-nolibm.h (isnanl): * lib/math.in.h (isnand, _gl_isnand, isnan): * lib/md4.c, lib/sha1.c: (rol): * lib/pagealign_alloc.c (pagealign_alloc, pagealign_free): * lib/ssfmalloc.h (allocate_block_from_pool): * lib/u64.h (u64hilo, u64lo, u64getlo) [INT_MAX < UINT64_MAX]: Use compound literal when it is safer than a cast and it pacifies -Wuseless-cast. * lib/fsusage.c (PROPAGATE_ALL_ONES): * lib/glthread/thread.h (glthread_atfork, glthread_sigmask): Parenthesize more. * lib/gettext.h (dgettext, dcgettext, dngettext, dcngettext) (bindtextdomain, bind_textdomain_codeset): Check types of unused args. --- diff --git a/ChangeLog b/ChangeLog index 654e73b3e7..2d26bbcd89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,57 @@ 2026-05-08 Paul Eggert + Pacify -Wuseless-cast via compound literals in lib + * lib/bitset.c (bitset_print): + * lib/bitset/list.c (LBITSET_ELT_BITS, debug_lbitset): + * lib/bitset/table.c (TBITSET_ELT_BITS): + * lib/bitsetv.c (bitsetv_dump, debug_bitsetv) + (bitsetv_matrix_dump): + * lib/gettext.h (gettext, ngettext, textdomain, bindtextdomain) + (bind_textdomain_codeset): + * lib/gl_anyavltree_list2.h (gl_tree_nx_add_first) + (gl_tree_nx_add_last, gl_tree_nx_add_before) + (gl_tree_nx_add_after): + * lib/gl_anylinked_list2.h (gl_linked_nx_create) + (gl_linked_node_nx_set_value, gl_linked_nx_set_at) + (gl_linked_search_from_to, gl_linked_indexof_from_to) + (gl_linked_nx_add_first, gl_linked_nx_add_last) + (gl_linked_nx_add_before, gl_linked_nx_add_after) + (gl_linked_nx_add_at): + * lib/gl_anyrbtree_list2.h (gl_tree_nx_add_first) + (gl_tree_nx_add_last, gl_tree_nx_add_before) + (gl_tree_nx_add_after): + * lib/gl_anytree_list2.h (gl_tree_node_nx_set_value) + (gl_tree_nx_set_at): + * lib/gl_anytreehash_list1.h (add_nodes_to_buckets): + * lib/gl_anytreehash_list2.h (gl_tree_search_from_to): + * lib/gl_array_list.c, lib/gl_carray_list.c, lib/gl_sublist.c: + (INDEX_TO_NODE): + * lib/gl_hash_map.c (gl_hash_search, gl_hash_nx_getput) + (gl_hash_getremove): + * lib/gl_hash_set.c (gl_hash_search, gl_hash_nx_add) + (gl_hash_remove): + * lib/gl_linkedhash_map.c (gl_linkedhash_search) + (gl_linkedhash_nx_getput, gl_linkedhash_getremove): + * lib/gl_linkedhash_set.c (gl_linkedhash_search) + (gl_linkedhash_nx_add, gl_linkedhash_remove): + * lib/isnand-nolibm.h (isnand): + * lib/isnanf-nolibm.h (isnanf): + * lib/isnanl-nolibm.h (isnanl): + * lib/math.in.h (isnand, _gl_isnand, isnan): + * lib/md4.c, lib/sha1.c: + (rol): + * lib/pagealign_alloc.c (pagealign_alloc, pagealign_free): + * lib/ssfmalloc.h (allocate_block_from_pool): + * lib/u64.h (u64hilo, u64lo, u64getlo) [INT_MAX < UINT64_MAX]: + Use compound literal when it is safer than a cast + and it pacifies -Wuseless-cast. + * lib/fsusage.c (PROPAGATE_ALL_ONES): + * lib/glthread/thread.h (glthread_atfork, glthread_sigmask): + Parenthesize more. + * lib/gettext.h (dgettext, dcgettext, dngettext, dcngettext) + (bindtextdomain, bind_textdomain_codeset): + Check types of unused args. + fstrcmp: pacify -Wuseless-cast * lib/fstrcmp.c (fstrcmp_bounded): Omit unnecessary cast of uintptr_t to uintptr_t. diff --git a/lib/bitset.c b/lib/bitset.c index caff36950a..7716aa405e 100644 --- a/lib/bitset.c +++ b/lib/bitset.c @@ -273,7 +273,7 @@ bitset_print (FILE *file, bitset bset, bool verbose) if (verbose) fprintf (file, "%s{n_bits = %lu, set = {", bitset_type_name_get (bset), - (unsigned long) bitset_size (bset)); + (unsigned long) {bitset_size (bset)}); unsigned pos = 30; bitset_bindex i; @@ -286,7 +286,7 @@ bitset_print (FILE *file, bitset bset, bool verbose) pos = 0; } - fprintf (file, "%lu ", (unsigned long) i); + fprintf (file, "%lu ", (unsigned long) {i}); pos += 1 + (i >= 10) + (i >= 100); } diff --git a/lib/bitset/list.c b/lib/bitset/list.c index f567edda33..9eeab77ab6 100644 --- a/lib/bitset/list.c +++ b/lib/bitset/list.c @@ -55,7 +55,7 @@ typedef bitset_word lbitset_word; /* Number of bits stored in each element. */ #define LBITSET_ELT_BITS \ - ((unsigned) (LBITSET_ELT_WORDS * LBITSET_WORD_BITS)) + ((unsigned) {LBITSET_ELT_WORDS * LBITSET_WORD_BITS}) /* Lbitset element. We use an array of bits for each element. These are linked together in a doubly-linked list. */ @@ -1272,7 +1272,7 @@ debug_lbitset (bitset bset) for (lbitset_elt *elt = LBITSET_HEAD (bset); elt; elt = elt->next) { - fprintf (stderr, "Elt %lu\n", (unsigned long) elt->index); + fprintf (stderr, "Elt %lu\n", (unsigned long) {elt->index}); for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++) { bitset_word word = elt->words[i]; diff --git a/lib/bitset/table.c b/lib/bitset/table.c index 0a28406ee6..866af8d817 100644 --- a/lib/bitset/table.c +++ b/lib/bitset/table.c @@ -53,7 +53,7 @@ /* Number of bits stored in each element. */ #define TBITSET_ELT_BITS \ - ((unsigned) (TBITSET_ELT_WORDS * BITSET_WORD_BITS)) + ((unsigned) {TBITSET_ELT_WORDS * BITSET_WORD_BITS}) /* Tbitset element. We use an array of bits. */ typedef struct tbitset_elt_struct diff --git a/lib/bitsetv.c b/lib/bitsetv.c index 7c91b29f30..0edcece393 100644 --- a/lib/bitsetv.c +++ b/lib/bitsetv.c @@ -132,7 +132,7 @@ bitsetv_dump (FILE *file, char const *title, char const *subtitle, fprintf (file, "%s\n", title); for (bitset_windex i = 0; bsetv[i]; i++) { - fprintf (file, "%s %lu\n", subtitle, (unsigned long) i); + fprintf (file, "%s %lu\n", subtitle, (unsigned long) {i}); bitset_dump (file, bsetv[i]); } @@ -145,7 +145,7 @@ debug_bitsetv (bitsetv bsetv) { for (bitset_windex i = 0; bsetv[i]; i++) { - fprintf (stderr, "%lu: ", (unsigned long) i); + fprintf (stderr, "%lu: ", (unsigned long) {i}); debug_bitset (bsetv[i]); } @@ -184,7 +184,7 @@ bitsetv_matrix_dump (FILE *out, const char *title, bitsetv bset) /* Contents. */ for (bitset_bindex i = 0; bset[i]; ++i) { - fprintf (out, "%2lu|", (unsigned long) i); + fprintf (out, "%2lu|", (unsigned long) {i}); for (bitset_bindex j = 0; j < hsize; ++j) fputs (bitset_test (bset[i], j) ? "1" : " ", out); fputs ("|\n", out); diff --git a/lib/fsusage.c b/lib/fsusage.c index 7c8c34f574..fbb38d7ab0 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/gettext.h b/lib/gettext.h index 894d4d9652..af84cbbf09 100644 --- a/lib/gettext.h +++ b/lib/gettext.h @@ -119,35 +119,37 @@ dcgettext (const char *domain, const char *msgid, int category) # pragma GCC diagnostic pop # endif # else -/* The casts to 'const char *' serve the purpose of producing warnings +/* The 'const char *' compound literals produce warnings for invalid uses of the value returned from these functions. */ # undef gettext -# define gettext(Msgid) ((const char *) (Msgid)) +# define gettext(Msgid) ((const char *) {(Msgid)}) # undef dgettext -# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) +# define dgettext(Domainname, Msgid) \ + ((void) (const char *) {(Domainname)}, gettext (Msgid)) # undef dcgettext # define dcgettext(Domainname, Msgid, Category) \ - ((void) (Category), dgettext (Domainname, Msgid)) + ((void) (const char *) {(Category)}, dgettext (Domainname, Msgid)) # endif # undef ngettext # define ngettext(Msgid1, Msgid2, N) \ ((N) == 1 \ - ? ((void) (Msgid2), (const char *) (Msgid1)) \ - : ((void) (Msgid1), (const char *) (Msgid2))) + ? ((void) (Msgid2), (const char *) {(Msgid1)}) \ + : ((void) (Msgid1), (const char *) {(Msgid2)})) # undef dngettext # define dngettext(Domainname, Msgid1, Msgid2, N) \ - ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) + ((void) (const char *) {(Domainname)}, ngettext (Msgid1, Msgid2, N)) # undef dcngettext # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ - ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N)) + ((void) (const char *) {(Category)}, \ + dngettext (Domainname, Msgid1, Msgid2, N)) # undef textdomain -# define textdomain(Domainname) ((const char *) (Domainname)) +# define textdomain(Domainname) ((const char *) {(Domainname)}) # undef bindtextdomain # define bindtextdomain(Domainname, Dirname) \ - ((void) (Domainname), (const char *) (Dirname)) + ((void) (const char *) {(Domainname)}, (const char *) {(Dirname)}) # undef bind_textdomain_codeset # define bind_textdomain_codeset(Domainname, Codeset) \ - ((void) (Domainname), (const char *) (Codeset)) + ((void) (const char *) {(Domainname)}, (const char *) {(Codeset)}) #endif diff --git a/lib/gl_anyavltree_list2.h b/lib/gl_anyavltree_list2.h index 071795b1e1..08e241b398 100644 --- a/lib/gl_anyavltree_list2.h +++ b/lib/gl_anyavltree_list2.h @@ -534,7 +534,7 @@ gl_tree_nx_add_first (gl_list_t list, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); #endif /* Add it to the tree. */ @@ -597,7 +597,7 @@ gl_tree_nx_add_last (gl_list_t list, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); #endif /* Add it to the tree. */ @@ -661,7 +661,7 @@ gl_tree_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); #endif /* Add it to the tree. */ @@ -726,7 +726,7 @@ gl_tree_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); #endif /* Add it to the tree. */ diff --git a/lib/gl_anylinked_list2.h b/lib/gl_anylinked_list2.h index 41c1785252..9fa25cf75a 100644 --- a/lib/gl_anylinked_list2.h +++ b/lib/gl_anylinked_list2.h @@ -123,7 +123,7 @@ gl_linked_nx_create (gl_list_implementation_t implementation, node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (node->value) - : (size_t)(uintptr_t) node->value); + : (size_t) {(uintptr_t) node->value}); /* Add node to the hash table. */ if (add_to_bucket (list, node) < 0) @@ -182,7 +182,7 @@ gl_linked_node_nx_set_value (_GL_ATTRIBUTE_MAYBE_UNUSED gl_list_t list, size_t new_hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); if (new_hashcode != node->h.hashcode) { @@ -297,7 +297,7 @@ gl_linked_nx_set_at (gl_list_t list, size_t position, const void *elt) size_t new_hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); if (new_hashcode != node->h.hashcode) { @@ -341,7 +341,7 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index, size_t hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); size_t bucket = hashcode % list->table_size; gl_listelement_equals_fn equals = list->base.equals_fn; @@ -495,7 +495,7 @@ gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, size_t hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); size_t bucket = hashcode % list->table_size; gl_listelement_equals_fn equals = list->base.equals_fn; @@ -616,7 +616,7 @@ gl_linked_nx_add_first (gl_list_t list, const void *elt) node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (node->value) - : (size_t)(uintptr_t) node->value); + : (size_t) {(uintptr_t) node->value}); /* Add node to the hash table. */ if (add_to_bucket (list, node) < 0) @@ -654,7 +654,7 @@ gl_linked_nx_add_last (gl_list_t list, const void *elt) node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (node->value) - : (size_t)(uintptr_t) node->value); + : (size_t) {(uintptr_t) node->value}); /* Add node to the hash table. */ if (add_to_bucket (list, node) < 0) @@ -692,7 +692,7 @@ gl_linked_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); /* Add new_node to the hash table. */ if (add_to_bucket (list, new_node) < 0) @@ -730,7 +730,7 @@ gl_linked_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); /* Add new_node to the hash table. */ if (add_to_bucket (list, new_node) < 0) @@ -773,7 +773,7 @@ gl_linked_nx_add_at (gl_list_t list, size_t position, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); /* Add new_node to the hash table. */ if (add_to_bucket (list, new_node) < 0) diff --git a/lib/gl_anyrbtree_list2.h b/lib/gl_anyrbtree_list2.h index 22007b21e1..7d0a003d9c 100644 --- a/lib/gl_anyrbtree_list2.h +++ b/lib/gl_anyrbtree_list2.h @@ -779,7 +779,7 @@ gl_tree_nx_add_first (gl_list_t list, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); #endif /* Add it to the tree. */ @@ -840,7 +840,7 @@ gl_tree_nx_add_last (gl_list_t list, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); #endif /* Add it to the tree. */ @@ -901,7 +901,7 @@ gl_tree_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); #endif /* Add it to the tree. */ @@ -956,7 +956,7 @@ gl_tree_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt) new_node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (new_node->value) - : (size_t)(uintptr_t) new_node->value); + : (size_t) {(uintptr_t) new_node->value}); #endif /* Add it to the tree. */ diff --git a/lib/gl_anytree_list2.h b/lib/gl_anytree_list2.h index ac0ca62154..edc5ce2b10 100644 --- a/lib/gl_anytree_list2.h +++ b/lib/gl_anytree_list2.h @@ -75,7 +75,7 @@ gl_tree_node_nx_set_value (_GL_ATTRIBUTE_MAYBE_UNUSED gl_list_t list, size_t new_hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); if (new_hashcode != node->h.hashcode) { @@ -216,7 +216,7 @@ gl_tree_nx_set_at (gl_list_t list, size_t position, const void *elt) size_t new_hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); if (new_hashcode != node->h.hashcode) { diff --git a/lib/gl_anytreehash_list1.h b/lib/gl_anytreehash_list1.h index b77d56cebc..665ecead66 100644 --- a/lib/gl_anytreehash_list1.h +++ b/lib/gl_anytreehash_list1.h @@ -289,7 +289,7 @@ add_nodes_to_buckets (gl_list_t list) node->h.hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (node->value) - : (size_t)(uintptr_t) node->value); + : (size_t) {(uintptr_t) node->value}); if (add_to_bucket (list, node) < 0) goto fail; /* Descend on right branch. */ diff --git a/lib/gl_anytreehash_list2.h b/lib/gl_anytreehash_list2.h index c28ff61c85..3f53f8bb01 100644 --- a/lib/gl_anytreehash_list2.h +++ b/lib/gl_anytreehash_list2.h @@ -29,7 +29,7 @@ gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index, size_t hashcode = (list->base.hashcode_fn != NULL ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); size_t bucket = hashcode % list->table_size; gl_listelement_equals_fn equals = list->base.equals_fn; @@ -63,7 +63,7 @@ gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *nodes_elt; if (gl_oset_search_atleast (nodes, compare_position_threshold, - (void *)(uintptr_t)start_index, + (void *)(uintptr_t) {start_index}, &nodes_elt)) { node = (gl_list_node_t) nodes_elt; diff --git a/lib/gl_array_list.c b/lib/gl_array_list.c index b9d36c9599..217b2d24ef 100644 --- a/lib/gl_array_list.c +++ b/lib/gl_array_list.c @@ -44,7 +44,7 @@ struct gl_list_impl /* struct gl_list_node_impl doesn't exist here. The pointers are actually indices + 1. */ -#define INDEX_TO_NODE(index) (gl_list_node_t)(uintptr_t)(size_t)((index) + 1) +#define INDEX_TO_NODE(index) (gl_list_node_t)(uintptr_t) {(index) + 1} #define NODE_TO_INDEX(node) ((uintptr_t)(node) - 1) static gl_list_t diff --git a/lib/gl_carray_list.c b/lib/gl_carray_list.c index 821b47dc82..0d43fcae16 100644 --- a/lib/gl_carray_list.c +++ b/lib/gl_carray_list.c @@ -47,7 +47,7 @@ struct gl_list_impl /* struct gl_list_node_impl doesn't exist here. The pointers are actually indices + 1. */ -#define INDEX_TO_NODE(index) (gl_list_node_t)(uintptr_t)(size_t)((index) + 1) +#define INDEX_TO_NODE(index) (gl_list_node_t)(uintptr_t) {(index) + 1} #define NODE_TO_INDEX(node) ((uintptr_t)(node) - 1) static gl_list_t diff --git a/lib/gl_hash_map.c b/lib/gl_hash_map.c index 03057a3de4..1598515641 100644 --- a/lib/gl_hash_map.c +++ b/lib/gl_hash_map.c @@ -101,7 +101,7 @@ gl_hash_search (gl_map_t map, const void *key, const void **valuep) size_t hashcode = (map->hashcode_fn != NULL ? map->hashcode_fn (key) - : (size_t)(uintptr_t) key); + : (size_t) {(uintptr_t) key}); size_t bucket = hashcode % map->table_size; gl_mapkey_equals_fn equals = map->base.equals_fn; @@ -127,7 +127,7 @@ gl_hash_nx_getput (gl_map_t map, const void *key, const void *value, size_t hashcode = (map->hashcode_fn != NULL ? map->hashcode_fn (key) - : (size_t)(uintptr_t) key); + : (size_t) {(uintptr_t) key}); size_t bucket = hashcode % map->table_size; gl_mapkey_equals_fn equals = map->base.equals_fn; @@ -174,7 +174,7 @@ gl_hash_getremove (gl_map_t map, const void *key, const void **oldvaluep) size_t hashcode = (map->hashcode_fn != NULL ? map->hashcode_fn (key) - : (size_t)(uintptr_t) key); + : (size_t) {(uintptr_t) key}); size_t bucket = hashcode % map->table_size; gl_mapkey_equals_fn equals = map->base.equals_fn; diff --git a/lib/gl_hash_set.c b/lib/gl_hash_set.c index 945ce46d8d..5d56b298e1 100644 --- a/lib/gl_hash_set.c +++ b/lib/gl_hash_set.c @@ -98,7 +98,7 @@ gl_hash_search (gl_set_t set, const void *elt) size_t hashcode = (set->hashcode_fn != NULL ? set->hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); size_t bucket = hashcode % set->table_size; gl_setelement_equals_fn equals = set->base.equals_fn; @@ -120,7 +120,7 @@ gl_hash_nx_add (gl_set_t set, const void *elt) size_t hashcode = (set->hashcode_fn != NULL ? set->hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); size_t bucket = hashcode % set->table_size; gl_setelement_equals_fn equals = set->base.equals_fn; @@ -162,7 +162,7 @@ gl_hash_remove (gl_set_t set, const void *elt) size_t hashcode = (set->hashcode_fn != NULL ? set->hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); size_t bucket = hashcode % set->table_size; gl_setelement_equals_fn equals = set->base.equals_fn; diff --git a/lib/gl_linkedhash_map.c b/lib/gl_linkedhash_map.c index d1839643ca..fd9e786128 100644 --- a/lib/gl_linkedhash_map.c +++ b/lib/gl_linkedhash_map.c @@ -126,7 +126,7 @@ gl_linkedhash_search (gl_map_t map, const void *key, const void **valuep) size_t hashcode = (map->hashcode_fn != NULL ? map->hashcode_fn (key) - : (size_t)(uintptr_t) key); + : (size_t) {(uintptr_t) key}); size_t bucket = hashcode % map->table_size; gl_mapkey_equals_fn equals = map->base.equals_fn; @@ -152,7 +152,7 @@ gl_linkedhash_nx_getput (gl_map_t map, const void *key, const void *value, size_t hashcode = (map->hashcode_fn != NULL ? map->hashcode_fn (key) - : (size_t)(uintptr_t) key); + : (size_t) {(uintptr_t) key}); size_t bucket = hashcode % map->table_size; gl_mapkey_equals_fn equals = map->base.equals_fn; @@ -203,7 +203,7 @@ gl_linkedhash_getremove (gl_map_t map, const void *key, const void **oldvaluep) size_t hashcode = (map->hashcode_fn != NULL ? map->hashcode_fn (key) - : (size_t)(uintptr_t) key); + : (size_t) {(uintptr_t) key}); size_t bucket = hashcode % map->table_size; gl_mapkey_equals_fn equals = map->base.equals_fn; diff --git a/lib/gl_linkedhash_set.c b/lib/gl_linkedhash_set.c index 97f8efc682..ec38bb53d2 100644 --- a/lib/gl_linkedhash_set.c +++ b/lib/gl_linkedhash_set.c @@ -123,7 +123,7 @@ gl_linkedhash_search (gl_set_t set, const void *elt) size_t hashcode = (set->hashcode_fn != NULL ? set->hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); size_t bucket = hashcode % set->table_size; gl_setelement_equals_fn equals = set->base.equals_fn; @@ -145,7 +145,7 @@ gl_linkedhash_nx_add (gl_set_t set, const void *elt) size_t hashcode = (set->hashcode_fn != NULL ? set->hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); size_t bucket = hashcode % set->table_size; gl_setelement_equals_fn equals = set->base.equals_fn; @@ -191,7 +191,7 @@ gl_linkedhash_remove (gl_set_t set, const void *elt) size_t hashcode = (set->hashcode_fn != NULL ? set->hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + : (size_t) {(uintptr_t) elt}); size_t bucket = hashcode % set->table_size; gl_setelement_equals_fn equals = set->base.equals_fn; diff --git a/lib/gl_sublist.c b/lib/gl_sublist.c index e4ce87e338..f882ec0fb9 100644 --- a/lib/gl_sublist.c +++ b/lib/gl_sublist.c @@ -40,7 +40,7 @@ struct gl_list_impl indices + 1. (We don't use the whole list's gl_list_node_t implementation, because gl_sublist_next_node and gl_sublist_previous_node would not be easy to implement with this choice.) */ -#define INDEX_TO_NODE(index) (gl_list_node_t)(uintptr_t)(size_t)((index) + 1) +#define INDEX_TO_NODE(index) (gl_list_node_t)(uintptr_t) {(index) + 1} #define NODE_TO_INDEX(node) ((uintptr_t)(node) - 1) static gl_list_t diff --git a/lib/glthread/thread.h b/lib/glthread/thread.h index f830657669..06ca8afdcf 100644 --- a/lib/glthread/thread.h +++ b/lib/glthread/thread.h @@ -118,7 +118,7 @@ extern _Noreturn void gl_thread_exit (void *return_value); ((void) (struct { void (*prepare_func) (void); \ void (*parent_func) (void); \ void (*child_func) (void); }) \ - { PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC }, \ + { (PREPARE_FUNC), (PARENT_FUNC), (CHILD_FUNC) }, \ 0) # ifdef __cplusplus @@ -249,7 +249,7 @@ extern const gl_thread_t gl_null_thread; ((void) (struct { void (*prepare_func) (void); \ void (*parent_func) (void); \ void (*child_func) (void); }) \ - { PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC }, \ + { (PREPARE_FUNC), (PARENT_FUNC), (CHILD_FUNC) }, \ 0) # endif @@ -280,7 +280,7 @@ typedef glwthread_thread_t gl_thread_t; # define glthread_sigmask(HOW, SET, OSET) \ /* unsupported */ \ ((void) (struct { int how; sigset_t const *set; sigset_t *oset; }) \ - { HOW, SET, OSET }, \ + { (HOW), (SET), (OSET) }, \ 0) # define glthread_join(THREAD, RETVALP) \ glwthread_thread_join (THREAD, RETVALP) @@ -294,7 +294,7 @@ typedef glwthread_thread_t gl_thread_t; ((void) (struct { void (*prepare_func) (void); \ void (*parent_func) (void); \ void (*child_func) (void); }) \ - { PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC }, \ + { (PREPARE_FUNC), (PARENT_FUNC), (CHILD_FUNC) }, \ 0) # ifdef __cplusplus @@ -318,7 +318,7 @@ typedef int gl_thread_t; ENOSYS) # define glthread_sigmask(HOW, SET, OSET) \ ((void) (struct { int how; sigset_t const *set; sigset_t *oset; }) \ - { HOW, SET, OSET }, \ + { (HOW), (SET), (OSET) }, \ 0) # define glthread_join(THREAD, RETVALP) \ ((void) (struct { gl_thread_t thread; void **retvalp; }) \ @@ -328,12 +328,12 @@ typedef int gl_thread_t; # define gl_thread_self_pointer() \ ((void *) gl_thread_self ()) # define gl_thread_exit(RETVAL) \ - ((void) (int) { RETVAL }) + ((void) (int) {(RETVAL)}) # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) \ ((void) (struct { void (*prepare_func) (void); \ void (*parent_func) (void); \ void (*child_func) (void); }) \ - { PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC }, \ + { (PREPARE_FUNC), (PARENT_FUNC), (CHILD_FUNC) }, \ 0) #endif diff --git a/lib/isnand-nolibm.h b/lib/isnand-nolibm.h index 70c5ecb42e..8a82d8d083 100644 --- a/lib/isnand-nolibm.h +++ b/lib/isnand-nolibm.h @@ -25,10 +25,10 @@ # if (__GNUC__ >= 4) || (__clang_major__ >= 4) /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. */ # undef isnand -# define isnand(x) __builtin_isnan ((double)(x)) +# define isnand(x) __builtin_isnan ((double) {(x)}) # else # undef isnand -# define isnand(x) isnan ((double)(x)) +# define isnand(x) isnan ((double) {(x)}) # endif #else /* Test whether X is a NaN. */ diff --git a/lib/isnanf-nolibm.h b/lib/isnanf-nolibm.h index 0ed965dbe6..860c9e516b 100644 --- a/lib/isnanf-nolibm.h +++ b/lib/isnanf-nolibm.h @@ -26,10 +26,10 @@ /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. GCC >= 4.0 also provides __builtin_isnanf, but clang doesn't. */ # undef isnanf -# define isnanf(x) __builtin_isnan ((float)(x)) +# define isnanf(x) __builtin_isnan ((float) {(x)}) # elif defined isnan # undef isnanf -# define isnanf(x) isnan ((float)(x)) +# define isnanf(x) isnan ((float) {(x)}) # endif #else /* Test whether X is a NaN. */ diff --git a/lib/isnanl-nolibm.h b/lib/isnanl-nolibm.h index 640f959e50..b7e1344c93 100644 --- a/lib/isnanl-nolibm.h +++ b/lib/isnanl-nolibm.h @@ -26,10 +26,10 @@ /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. GCC >= 4.0 also provides __builtin_isnanl, but clang doesn't. */ # undef isnanl -# define isnanl(x) __builtin_isnan ((long double)(x)) +# define isnanl(x) __builtin_isnan ((long double) {(x)}) # elif defined isnan # undef isnanl -# define isnanl(x) isnan ((long double)(x)) +# define isnanl(x) isnan ((long double) {(x)}) # endif #else /* Test whether X is a NaN. */ diff --git a/lib/malloca.h b/lib/malloca.h index 5fb955e5f7..6d2156d411 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/math.in.h b/lib/math.in.h index 216c203a60..89dfb9307d 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -2588,10 +2588,10 @@ _GL_EXTERN_C int isnand (double x); # if (__GNUC__ >= 4) || (__clang_major__ >= 4) /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. */ # undef isnand -# define isnand(x) __builtin_isnan ((double)(x)) +# define isnand(x) __builtin_isnan ((double) {(x)}) # elif !defined HAVE_ISNAND_NOLIBM # undef isnand -# define isnand(x) isnan ((double)(x)) +# define isnand(x) isnan ((double) {(x)}) # endif # endif # else @@ -2638,7 +2638,7 @@ _GL_EXTERN_C int rpl_isnanf (float x); # define _gl_isnanf(x) rpl_isnanf (x) # endif # if @HAVE_ISNAND@ && (__GNUC__ >= 4) || (__clang_major__ >= 4) -# define _gl_isnand(x) __builtin_isnan ((double)(x)) +# define _gl_isnand(x) __builtin_isnan ((double) {(x)}) # else _GL_EXTERN_C int rpl_isnand (double x); # define _gl_isnand(x) rpl_isnand (x) @@ -2672,9 +2672,11 @@ template <> inline int isnan (long double x) { return __builtin_isn # else # undef isnan # define isnan(x) \ - (sizeof (x) == sizeof (long double) ? __builtin_isnan ((long double)(x)) : \ - sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \ - __builtin_isnan ((float)(x))) + (sizeof (x) == sizeof (long double) \ + ? __builtin_isnan ((long double) {(x)}) \ + : sizeof (x) == sizeof (double) \ + ? __builtin_isnan ((double) {(x)}) \ + : __builtin_isnan ((float) {(x)})) # endif # endif # if @GNULIB_ISNAN@ && defined __cplusplus diff --git a/lib/md4.c b/lib/md4.c index fe34886140..ba3a9f4bd6 100644 --- a/lib/md4.c +++ b/lib/md4.c @@ -199,7 +199,7 @@ md4_process_bytes (void const *restrict buffer, size_t len, #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) #define H(x, y, z) ((x) ^ (y) ^ (z)) -#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n)))) +#define rol(x, n) (((x) << (n)) | ((uint32_t) {(x)} >> (32 - (n)))) #define R1(a,b,c,d,k,s) a=rol(a+F(b,c,d)+x[k],s); #define R2(a,b,c,d,k,s) a=rol(a+G(b,c,d)+x[k]+K1,s); #define R3(a,b,c,d,k,s) a=rol(a+H(b,c,d)+x[k]+K2,s); diff --git a/lib/pagealign_alloc.c b/lib/pagealign_alloc.c index 1d7d49fd39..f01b61ebe5 100644 --- a/lib/pagealign_alloc.c +++ b/lib/pagealign_alloc.c @@ -155,7 +155,7 @@ pagealign_alloc (size_t size) if (page_info_map == NULL) page_info_map = gl_map_create_empty (GL_HASH_MAP, NULL, NULL, NULL, NULL); - gl_map_put (page_info_map, ret, (void *) (uintptr_t) size); + gl_map_put (page_info_map, ret, (void *) (uintptr_t) {size}); break; #else errno = ENOSYS; @@ -248,7 +248,7 @@ pagealign_free (void *aligned_ptr) if (page_info_map == NULL || !gl_map_getremove (page_info_map, aligned_ptr, &value)) abort (); - if (munmap (aligned_ptr, (size_t) (uintptr_t) value) < 0) + if (munmap (aligned_ptr, (size_t) {(uintptr_t) value}) < 0) error (EXIT_FAILURE, errno, "Failed to unmap memory"); } break; diff --git a/lib/sha1.c b/lib/sha1.c index bb7aa2af29..150e38ea47 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -240,7 +240,7 @@ sha1_process_block (void const *restrict buffer, size_t len, ctx->total[0] += lolen; ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < lolen); -#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n)))) +#define rol(x, n) (((x) << (n)) | ((uint32_t) {(x)} >> (32 - (n)))) #define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \ ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \ diff --git a/lib/ssfmalloc.h b/lib/ssfmalloc.h index f04f6e9ccf..603b7eb768 100644 --- a/lib/ssfmalloc.h +++ b/lib/ssfmalloc.h @@ -718,7 +718,7 @@ allocate_block_from_pool (size_t size, struct page_pool *pool) gl_oset_iterator_t iter = gl_oset_iterator_atleast (pool->managed_pages, page_free_space_is_at_least, - (void *) (uintptr_t) size); + (void *) (uintptr_t) {size}); const void *elt; while (gl_oset_iterator_next (&iter, &elt)) { diff --git a/lib/u64.h b/lib/u64.h index 2f9c791815..9274cb8182 100644 --- a/lib/u64.h +++ b/lib/u64.h @@ -46,10 +46,10 @@ extern "C" { /* Native implementations are trivial. See below for comments on what these operations do. */ typedef uint64_t u64; -# define u64hilo(hi, lo) ((u64) (((u64) (hi) << 32) + (lo))) +# define u64hilo(hi, lo) ((u64) {((u64) {(hi)} << 32) + (lo)}) # define u64init(hi, lo) u64hilo (hi, lo) -# define u64lo(x) ((u64) (x)) -# define u64getlo(x) ((uint32_t) ((x) & UINT32_MAX)) +# define u64lo(x) ((u64) {(x)}) +# define u64getlo(x) ((uint32_t) {(x) & UINT32_MAX}) # define u64size(x) u64lo (x) # define u64not(x) (~(x)) # define u64lt(x, y) ((x) < (y))