From 71f4f452e4768606c6f81300887e3e9c6ca74a93 Mon Sep 17 00:00:00 2001 From: Dylan Cali Date: Sat, 6 Sep 2014 01:52:31 -0500 Subject: [PATCH] build: fix gcc warnings * tests/test-avltree_list.c: Remove gl_avltree_list_check_invariants declaration * lib/gl_avltree_list.c: Add gl_avltree_list_check_invariants declaration from test-avltree_list.c. Fixes gcc warning about missing declaration. * lib/gl_avltree_list.c: (check_invariants): Add pure attribute. (gl_avltree_list_check_invariants): Add const attribute. Also use a gcc pragma to ignore a false positive warning about check_invariants being a statement with no effect (only for gcc >= 4.6). * lib/gl_anytree_list2.h: Add pure attribute to (gl_tree_node_value), (gl_tree_next_node), (gl_tree_previous_node), (node_at), (gl_tree_get_at) --- lib/gl_anytree_list2.h | 10 +++++----- lib/gl_avltree_list.c | 18 ++++++++++++++++-- tests/test-avltree_list.c | 2 -- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/gl_anytree_list2.h b/lib/gl_anytree_list2.h index 70e59a5..05fde15 100644 --- a/lib/gl_anytree_list2.h +++ b/lib/gl_anytree_list2.h @@ -59,7 +59,7 @@ gl_tree_size (gl_list_t list) return (list->root != NULL ? list->root->branch_size : 0); } -static const void * +static const void * _GL_ATTRIBUTE_PURE gl_tree_node_value (gl_list_t list, gl_list_node_t node) { return node->value; @@ -100,7 +100,7 @@ gl_tree_node_nx_set_value (gl_list_t list, gl_list_node_t node, const void *elt) return 0; } -static gl_list_node_t +static gl_list_node_t _GL_ATTRIBUTE_PURE gl_tree_next_node (gl_list_t list, gl_list_node_t node) { if (node->right != NULL) @@ -118,7 +118,7 @@ gl_tree_next_node (gl_list_t list, gl_list_node_t node) return node; } -static gl_list_node_t +static gl_list_node_t _GL_ATTRIBUTE_PURE gl_tree_previous_node (gl_list_t list, gl_list_node_t node) { if (node->left != NULL) @@ -137,7 +137,7 @@ gl_tree_previous_node (gl_list_t list, gl_list_node_t node) } /* Return the node at the given position < gl_tree_size (list). */ -static gl_list_node_t +static gl_list_node_t _GL_ATTRIBUTE_PURE node_at (gl_list_node_t root, size_t position) { /* Here we know that root != NULL. */ @@ -162,7 +162,7 @@ node_at (gl_list_node_t root, size_t position) return node; } -static const void * +static const void * _GL_ATTRIBUTE_PURE gl_tree_get_at (gl_list_t list, size_t position) { gl_list_node_t node = list->root; diff --git a/lib/gl_avltree_list.c b/lib/gl_avltree_list.c index 1afe5ca..0466029 100644 --- a/lib/gl_avltree_list.c +++ b/lib/gl_avltree_list.c @@ -36,8 +36,10 @@ /* Generic binary tree code. */ #include "gl_anytree_list2.h" +extern void gl_avltree_list_check_invariants (gl_list_t list); + /* For debugging. */ -static unsigned int +static unsigned int _GL_ATTRIBUTE_PURE check_invariants (gl_list_node_t node, gl_list_node_t parent) { unsigned int left_height = @@ -59,13 +61,25 @@ check_invariants (gl_list_node_t node, gl_list_node_t parent) return 1 + (left_height > right_height ? left_height : right_height); } -void + +/* GCC warns that check_invariants has no effect, but it does. Ignore + the false positive. */ +#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-value" +#endif + +void _GL_ATTRIBUTE_CONST gl_avltree_list_check_invariants (gl_list_t list) { if (list->root != NULL) check_invariants (list->root, NULL); } +#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic pop +#endif + const struct gl_list_implementation gl_avltree_list_implementation = { gl_tree_nx_create_empty, diff --git a/tests/test-avltree_list.c b/tests/test-avltree_list.c index 1c0331a..c877c09 100644 --- a/tests/test-avltree_list.c +++ b/tests/test-avltree_list.c @@ -25,8 +25,6 @@ #include "progname.h" #include "macros.h" -extern void gl_avltree_list_check_invariants (gl_list_t list); - static const char *objects[15] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o" -- 2.1.0