bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* list: fix GCC warnings
@ 2020-05-31  7:05 Akim Demaille
  2020-05-31  9:28 ` Bruno Haible
  0 siblings, 1 reply; 3+ messages in thread
From: Akim Demaille @ 2020-05-31  7:05 UTC (permalink / raw)
  To: Gnulib bugs

Hi all,

There's one case debatable case: the functions that may actually
use the argument depending on macros.  For instance

static int
gl_linked_node_nx_set_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
                             gl_list_node_t node,
                             const void *elt)
{
#if WITH_HASHTABLE
  if (elt != node->value)
    {
      size_t new_hashcode =
        (list->base.hashcode_fn != NULL
         ? list->base.hashcode_fn (elt)
         : (size_t)(uintptr_t) elt);
...
    }
#else
  node->value = elt;
#endif
  return 0;
}

I don't think the MAYBE_UNUSED attribute may harm in any way, but if we
want to avoid that, the simplest would probably be to move the #if outside
and implement the function twice.

Cheers!


commit a49be9d81e795a3f80bd08a4cfcdd74e9cd8b636
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sun May 31 08:59:25 2020 +0200

    list: fix GCC warnings
    
    * lib/gl_anytree_list2.h (gl_tree_iterator_free)
    (gl_tree_next_node, gl_tree_node_nx_set_value)
    (gl_tree_previous_node, gl_tree_next_node):
    Mark unused arguments.
    * lib/gl_anytree_oset.h (gl_tree_iterator_free): Likewise.
    * lib/gl_anylinked_list2.h (gl_linked_node_value)
    (gl_linked_node_nx_set_value, gl_linked_iterator_free): Likewise.
    
    * lib/gl_anytreehash_list2.h (gl_tree_search_from_to): Avoid using
    the same variable name in nested scopes.

diff --git a/ChangeLog b/ChangeLog
index e8133349c..7b2c01b68 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2020-05-31  Akim Demaille  <akim@lrde.epita.fr>
+
+	list: fix GCC warnings
+	* lib/gl_anytree_list2.h (gl_tree_iterator_free)
+	(gl_tree_next_node, gl_tree_node_nx_set_value)
+	(gl_tree_previous_node, gl_tree_next_node):
+	Mark unused arguments.
+	* lib/gl_anytree_oset.h (gl_tree_iterator_free): Likewise.
+	* lib/gl_anylinked_list2.h (gl_linked_node_value)
+	(gl_linked_node_nx_set_value, gl_linked_iterator_free): Likewise.
+
+	* lib/gl_anytreehash_list2.h (gl_tree_search_from_to): Avoid using
+	the same variable name in nested scopes.
+
 2020-05-30  Bruno Haible  <bruno@clisp.org>
 
 	wmemchr: Relicense under LGPLv2+.
diff --git a/lib/gl_anylinked_list2.h b/lib/gl_anylinked_list2.h
index 114106c7d..3e01f8fa0 100644
--- a/lib/gl_anylinked_list2.h
+++ b/lib/gl_anylinked_list2.h
@@ -76,11 +76,11 @@ gl_linked_nx_create_empty (gl_list_implementation_t implementation,
 
 static gl_list_t
 gl_linked_nx_create (gl_list_implementation_t implementation,
-                  gl_listelement_equals_fn equals_fn,
-                  gl_listelement_hashcode_fn hashcode_fn,
-                  gl_listelement_dispose_fn dispose_fn,
-                  bool allow_duplicates,
-                  size_t count, const void **contents)
+                     gl_listelement_equals_fn equals_fn,
+                     gl_listelement_hashcode_fn hashcode_fn,
+                     gl_listelement_dispose_fn dispose_fn,
+                     bool allow_duplicates,
+                     size_t count, const void **contents)
 {
   struct gl_list_impl *list =
     (struct gl_list_impl *) malloc (sizeof (struct gl_list_impl));
@@ -170,13 +170,15 @@ gl_linked_size (gl_list_t list)
 }
 
 static const void * _GL_ATTRIBUTE_PURE
-gl_linked_node_value (gl_list_t list, gl_list_node_t node)
+gl_linked_node_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                      gl_list_node_t node)
 {
   return node->value;
 }
 
 static int
-gl_linked_node_nx_set_value (gl_list_t list, gl_list_node_t node,
+gl_linked_node_nx_set_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                             gl_list_node_t node,
                              const void *elt)
 {
 #if WITH_HASHTABLE
@@ -1021,7 +1023,7 @@ gl_linked_iterator_next (gl_list_iterator_t *iterator,
 }
 
 static void
-gl_linked_iterator_free (gl_list_iterator_t *iterator)
+gl_linked_iterator_free (gl_list_iterator_t *iterator _GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
 
diff --git a/lib/gl_anytree_list2.h b/lib/gl_anytree_list2.h
index c5a67dbd0..939b79748 100644
--- a/lib/gl_anytree_list2.h
+++ b/lib/gl_anytree_list2.h
@@ -60,13 +60,15 @@ gl_tree_size (gl_list_t list)
 }
 
 static const void *
-gl_tree_node_value (gl_list_t list, gl_list_node_t node)
+gl_tree_node_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                    gl_list_node_t node)
 {
   return node->value;
 }
 
 static int
-gl_tree_node_nx_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
+gl_tree_node_nx_set_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                           gl_list_node_t node, const void *elt)
 {
 #if WITH_HASHTABLE
   if (elt != node->value)
@@ -101,7 +103,8 @@ gl_tree_node_nx_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
 }
 
 static gl_list_node_t _GL_ATTRIBUTE_PURE
-gl_tree_next_node (gl_list_t list, gl_list_node_t node)
+gl_tree_next_node (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                   gl_list_node_t node)
 {
   if (node->right != NULL)
     {
@@ -119,7 +122,8 @@ gl_tree_next_node (gl_list_t list, gl_list_node_t node)
 }
 
 static gl_list_node_t _GL_ATTRIBUTE_PURE
-gl_tree_previous_node (gl_list_t list, gl_list_node_t node)
+gl_tree_previous_node (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                       gl_list_node_t node)
 {
   if (node->left != NULL)
     {
@@ -628,7 +632,7 @@ gl_tree_iterator_next (gl_list_iterator_t *iterator,
 }
 
 static void
-gl_tree_iterator_free (gl_list_iterator_t *iterator)
+gl_tree_iterator_free (gl_list_iterator_t *iterator  _GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
 
diff --git a/lib/gl_anytree_oset.h b/lib/gl_anytree_oset.h
index e837f6324..d737e313d 100644
--- a/lib/gl_anytree_oset.h
+++ b/lib/gl_anytree_oset.h
@@ -292,6 +292,6 @@ gl_tree_iterator_next (gl_oset_iterator_t *iterator, const void **eltp)
 }
 
 static void
-gl_tree_iterator_free (gl_oset_iterator_t *iterator)
+gl_tree_iterator_free (gl_oset_iterator_t *iterator  _GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
diff --git a/lib/gl_anytreehash_list2.h b/lib/gl_anytreehash_list2.h
index 69e6776b0..762f8c85a 100644
--- a/lib/gl_anytreehash_list2.h
+++ b/lib/gl_anytreehash_list2.h
@@ -61,13 +61,13 @@ gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
                         {
                           /* We have to return only the one at the minimal
                              position >= start_index.  */
-                          const void *elt;
+                          const void *p;
                           if (gl_oset_search_atleast (nodes,
                                                       compare_position_threshold,
                                                       (void *)(uintptr_t)start_index,
-                                                      &elt))
+                                                      &p))
                             {
-                              node = (gl_list_node_t) elt;
+                              node = (gl_list_node_t) p;
                               if (end_index == list->root->branch_size
                                   || node_position (node) < end_index)
                                 return node;



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: list: fix GCC warnings
  2020-05-31  7:05 list: fix GCC warnings Akim Demaille
@ 2020-05-31  9:28 ` Bruno Haible
  2020-05-31 10:43   ` Akim Demaille
  0 siblings, 1 reply; 3+ messages in thread
From: Bruno Haible @ 2020-05-31  9:28 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Akim Demaille

Hi Akim,

Thanks for caring about these warnings.

>     * lib/gl_anytree_list2.h (gl_tree_iterator_free)
>     (gl_tree_next_node, gl_tree_node_nx_set_value)
>     (gl_tree_previous_node, gl_tree_next_node):
>     Mark unused arguments.
>     * lib/gl_anytree_oset.h (gl_tree_iterator_free): Likewise.
>     * lib/gl_anylinked_list2.h (gl_linked_node_value)
>     (gl_linked_node_nx_set_value, gl_linked_iterator_free): Likewise.

This part looks good.

>     * lib/gl_anytreehash_list2.h (gl_tree_search_from_to): Avoid using
>     the same variable name in nested scopes.

'p' is a poor variable name here. Please, can use you 'nodes_elt' instead?

> static int
> gl_linked_node_nx_set_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
>                              gl_list_node_t node,
>                              const void *elt)
> {
> #if WITH_HASHTABLE
>   if (elt != node->value)
>     {
>       size_t new_hashcode =
>         (list->base.hashcode_fn != NULL
>          ? list->base.hashcode_fn (elt)
>          : (size_t)(uintptr_t) elt);
> ...
>     }
> #else
>   node->value = elt;
> #endif
>   return 0;
> }
> 
> I don't think the MAYBE_UNUSED attribute may harm in any way, but if we
> want to avoid that, the simplest would probably be to move the #if outside
> and implement the function twice.

Better use _GL_ATTRIBUTE_MAYBE_UNUSED. Implementing the function twice means
  - duplicating the parameter list,
  - having no proper place for attaching a comment to the function.

Bruno



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: list: fix GCC warnings
  2020-05-31  9:28 ` Bruno Haible
@ 2020-05-31 10:43   ` Akim Demaille
  0 siblings, 0 replies; 3+ messages in thread
From: Akim Demaille @ 2020-05-31 10:43 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib



> Le 31 mai 2020 à 11:28, Bruno Haible <bruno@clisp.org> a écrit :
> 
> Hi Akim,
> 
> Thanks for caring about these warnings.

Sure!

>>    * lib/gl_anytreehash_list2.h (gl_tree_search_from_to): Avoid using
>>    the same variable name in nested scopes.
> 
> 'p' is a poor variable name here. Please, can use you 'nodes_elt' instead?

Good with me.

>> I don't think the MAYBE_UNUSED attribute may harm in any way, but if we
>> want to avoid that, the simplest would probably be to move the #if outside
>> and implement the function twice.
> 
> Better use _GL_ATTRIBUTE_MAYBE_UNUSED. Implementing the function twice means
>  - duplicating the parameter list,
>  - having no proper place for attaching a comment to the function.

Very much agreed.  Installed as follows.

Cheers!

commit d8a8fb3423499851bf06aac2302112944a276f97
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sun May 31 08:59:25 2020 +0200

    list: fix GCC warnings
    
    * lib/gl_anytree_list2.h (gl_tree_iterator_free)
    (gl_tree_next_node, gl_tree_node_nx_set_value)
    (gl_tree_previous_node, gl_tree_next_node):
    Mark unused arguments.
    * lib/gl_anytree_oset.h (gl_tree_iterator_free): Likewise.
    * lib/gl_anylinked_list2.h (gl_linked_node_value)
    (gl_linked_node_nx_set_value, gl_linked_iterator_free): Likewise.
    
    * lib/gl_anytreehash_list2.h (gl_tree_search_from_to): Avoid using
    the same variable name in nested scopes.

diff --git a/ChangeLog b/ChangeLog
index 321d5e28c..5ef05e037 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2020-05-31  Akim Demaille  <akim@lrde.epita.fr>
+
+	list: fix GCC warnings
+	* lib/gl_anytree_list2.h (gl_tree_iterator_free)
+	(gl_tree_next_node, gl_tree_node_nx_set_value)
+	(gl_tree_previous_node, gl_tree_next_node):
+	Mark unused arguments.
+	* lib/gl_anytree_oset.h (gl_tree_iterator_free): Likewise.
+	* lib/gl_anylinked_list2.h (gl_linked_node_value)
+	(gl_linked_node_nx_set_value, gl_linked_iterator_free): Likewise.
+
+	* lib/gl_anytreehash_list2.h (gl_tree_search_from_to): Avoid using
+	the same variable name in nested scopes.
+
 2020-05-31  Bruno Haible  <bruno@clisp.org>
 
 	list-c++, set-c++, oset-c++, map-c++, omap-c++: Don't fool the compiler.
diff --git a/lib/gl_anylinked_list2.h b/lib/gl_anylinked_list2.h
index 114106c7d..3e01f8fa0 100644
--- a/lib/gl_anylinked_list2.h
+++ b/lib/gl_anylinked_list2.h
@@ -76,11 +76,11 @@ gl_linked_nx_create_empty (gl_list_implementation_t implementation,
 
 static gl_list_t
 gl_linked_nx_create (gl_list_implementation_t implementation,
-                  gl_listelement_equals_fn equals_fn,
-                  gl_listelement_hashcode_fn hashcode_fn,
-                  gl_listelement_dispose_fn dispose_fn,
-                  bool allow_duplicates,
-                  size_t count, const void **contents)
+                     gl_listelement_equals_fn equals_fn,
+                     gl_listelement_hashcode_fn hashcode_fn,
+                     gl_listelement_dispose_fn dispose_fn,
+                     bool allow_duplicates,
+                     size_t count, const void **contents)
 {
   struct gl_list_impl *list =
     (struct gl_list_impl *) malloc (sizeof (struct gl_list_impl));
@@ -170,13 +170,15 @@ gl_linked_size (gl_list_t list)
 }
 
 static const void * _GL_ATTRIBUTE_PURE
-gl_linked_node_value (gl_list_t list, gl_list_node_t node)
+gl_linked_node_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                      gl_list_node_t node)
 {
   return node->value;
 }
 
 static int
-gl_linked_node_nx_set_value (gl_list_t list, gl_list_node_t node,
+gl_linked_node_nx_set_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                             gl_list_node_t node,
                              const void *elt)
 {
 #if WITH_HASHTABLE
@@ -1021,7 +1023,7 @@ gl_linked_iterator_next (gl_list_iterator_t *iterator,
 }
 
 static void
-gl_linked_iterator_free (gl_list_iterator_t *iterator)
+gl_linked_iterator_free (gl_list_iterator_t *iterator _GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
 
diff --git a/lib/gl_anytree_list2.h b/lib/gl_anytree_list2.h
index c5a67dbd0..939b79748 100644
--- a/lib/gl_anytree_list2.h
+++ b/lib/gl_anytree_list2.h
@@ -60,13 +60,15 @@ gl_tree_size (gl_list_t list)
 }
 
 static const void *
-gl_tree_node_value (gl_list_t list, gl_list_node_t node)
+gl_tree_node_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                    gl_list_node_t node)
 {
   return node->value;
 }
 
 static int
-gl_tree_node_nx_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
+gl_tree_node_nx_set_value (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                           gl_list_node_t node, const void *elt)
 {
 #if WITH_HASHTABLE
   if (elt != node->value)
@@ -101,7 +103,8 @@ gl_tree_node_nx_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
 }
 
 static gl_list_node_t _GL_ATTRIBUTE_PURE
-gl_tree_next_node (gl_list_t list, gl_list_node_t node)
+gl_tree_next_node (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                   gl_list_node_t node)
 {
   if (node->right != NULL)
     {
@@ -119,7 +122,8 @@ gl_tree_next_node (gl_list_t list, gl_list_node_t node)
 }
 
 static gl_list_node_t _GL_ATTRIBUTE_PURE
-gl_tree_previous_node (gl_list_t list, gl_list_node_t node)
+gl_tree_previous_node (gl_list_t list _GL_ATTRIBUTE_MAYBE_UNUSED,
+                       gl_list_node_t node)
 {
   if (node->left != NULL)
     {
@@ -628,7 +632,7 @@ gl_tree_iterator_next (gl_list_iterator_t *iterator,
 }
 
 static void
-gl_tree_iterator_free (gl_list_iterator_t *iterator)
+gl_tree_iterator_free (gl_list_iterator_t *iterator  _GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
 
diff --git a/lib/gl_anytree_oset.h b/lib/gl_anytree_oset.h
index e837f6324..d737e313d 100644
--- a/lib/gl_anytree_oset.h
+++ b/lib/gl_anytree_oset.h
@@ -292,6 +292,6 @@ gl_tree_iterator_next (gl_oset_iterator_t *iterator, const void **eltp)
 }
 
 static void
-gl_tree_iterator_free (gl_oset_iterator_t *iterator)
+gl_tree_iterator_free (gl_oset_iterator_t *iterator  _GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
diff --git a/lib/gl_anytreehash_list2.h b/lib/gl_anytreehash_list2.h
index 69e6776b0..26e52bf38 100644
--- a/lib/gl_anytreehash_list2.h
+++ b/lib/gl_anytreehash_list2.h
@@ -61,13 +61,13 @@ gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
                         {
                           /* We have to return only the one at the minimal
                              position >= start_index.  */
-                          const void *elt;
+                          const void *nodes_elt;
                           if (gl_oset_search_atleast (nodes,
                                                       compare_position_threshold,
                                                       (void *)(uintptr_t)start_index,
-                                                      &elt))
+                                                      &nodes_elt))
                             {
-                              node = (gl_list_node_t) elt;
+                              node = (gl_list_node_t) nodes_elt;
                               if (end_index == list->root->branch_size
                                   || node_position (node) < end_index)
                                 return node;



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-31 10:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-31  7:05 list: fix GCC warnings Akim Demaille
2020-05-31  9:28 ` Bruno Haible
2020-05-31 10:43   ` Akim Demaille

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).