bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

list: fix GCC warnings


From: Akim Demaille
Subject: list: fix GCC warnings
Date: Sun, 31 May 2020 09:05:32 +0200

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;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]