bug-gnulib
[Top][All Lists]
Advanced

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

Re: 'const' function attribute


From: Bruno Haible
Subject: Re: 'const' function attribute
Date: Sun, 18 Oct 2020 16:27:35 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-189-generic; KDE/5.18.0; x86_64; ; )

Paul Eggert wrote:
> > To me, this is a pointless warning. Would you agree that a bug report to
> > the GCC people makes sense?
> 
> Yes and no. Theoretically, it makes sense that 'const' could apply to static 
> functions too. However the practical argument is weak. Programmers shouldn't 
> be 
> bothering with 'const' on static functions, since the compiler should figure 
> it 
> out. And with extern functions, 'const' would mean the API requires that the 
> function is a no-op, which is a pretty small niche case.

Indeed. Although GCC and clang don't have the same behaviour here (GCC gives
a warning, clang does not), it's pointless to declare that a public function
that returns 'void' has no side effects - because that is an implementation
detail that is subject to change.

So, not worth bothering the GCC people.


2020-10-18  Bruno Haible  <bruno@clisp.org>

        *-list, *-oset, *-omap: Avoid a GCC warning (regression 2020-10-10).
        * lib/gl_anylinked_list2.h (gl_linked_iterator_free): Remove
        '_GL_ATTRIBUTE_CONST'.
        * lib/gl_anytree_list2.h (gl_tree_iterator_free): Likewise.
        * lib/gl_anytree_omap.h (gl_tree_iterator_free): Likewise.
        * lib/gl_anytree_oset.h (gl_tree_iterator_free): Likewise.
        * lib/gl_array_list.c (gl_array_iterator_free): Likewise.
        * lib/gl_array_omap.c (gl_array_iterator_free): Likewise.
        * lib/gl_array_oset.c (gl_array_iterator_free): Likewise.
        * lib/gl_carray_list.c (gl_carray_iterator_free): Likewise.

diff --git a/lib/gl_anylinked_list2.h b/lib/gl_anylinked_list2.h
index bc9d5c7..24ef47e 100644
--- a/lib/gl_anylinked_list2.h
+++ b/lib/gl_anylinked_list2.h
@@ -1022,7 +1022,7 @@ gl_linked_iterator_next (gl_list_iterator_t *iterator,
     return false;
 }
 
-static void _GL_ATTRIBUTE_CONST
+static void
 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 3cb3422..ae4d419 100644
--- a/lib/gl_anytree_list2.h
+++ b/lib/gl_anytree_list2.h
@@ -631,7 +631,7 @@ gl_tree_iterator_next (gl_list_iterator_t *iterator,
     return false;
 }
 
-static void _GL_ATTRIBUTE_CONST
+static void
 gl_tree_iterator_free (gl_list_iterator_t *iterator  
_GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
diff --git a/lib/gl_anytree_omap.h b/lib/gl_anytree_omap.h
index 016c83b..d8658c2 100644
--- a/lib/gl_anytree_omap.h
+++ b/lib/gl_anytree_omap.h
@@ -299,7 +299,7 @@ gl_tree_iterator_next (gl_omap_iterator_t *iterator,
     return false;
 }
 
-static void _GL_ATTRIBUTE_CONST
+static void
 gl_tree_iterator_free (gl_omap_iterator_t *iterator _GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
diff --git a/lib/gl_anytree_oset.h b/lib/gl_anytree_oset.h
index 46c47c2..5b3ab13 100644
--- a/lib/gl_anytree_oset.h
+++ b/lib/gl_anytree_oset.h
@@ -437,7 +437,7 @@ gl_tree_iterator_next (gl_oset_iterator_t *iterator, const 
void **eltp)
     return false;
 }
 
-static void _GL_ATTRIBUTE_CONST
+static void
 gl_tree_iterator_free (gl_oset_iterator_t *iterator _GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
diff --git a/lib/gl_array_list.c b/lib/gl_array_list.c
index 92bf463..3d9020e 100644
--- a/lib/gl_array_list.c
+++ b/lib/gl_array_list.c
@@ -508,7 +508,7 @@ gl_array_iterator_next (gl_list_iterator_t *iterator,
     return false;
 }
 
-static void _GL_ATTRIBUTE_CONST
+static void
 gl_array_iterator_free (gl_list_iterator_t *iterator 
_GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
diff --git a/lib/gl_array_omap.c b/lib/gl_array_omap.c
index c3117db..2bc5f5e 100644
--- a/lib/gl_array_omap.c
+++ b/lib/gl_array_omap.c
@@ -369,7 +369,7 @@ gl_array_iterator_next (gl_omap_iterator_t *iterator,
     return false;
 }
 
-static void _GL_ATTRIBUTE_CONST
+static void
 gl_array_iterator_free (gl_omap_iterator_t *iterator 
_GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
diff --git a/lib/gl_array_oset.c b/lib/gl_array_oset.c
index 5fb0da1..7832abc 100644
--- a/lib/gl_array_oset.c
+++ b/lib/gl_array_oset.c
@@ -487,7 +487,7 @@ gl_array_iterator_next (gl_oset_iterator_t *iterator, const 
void **eltp)
     return false;
 }
 
-static void _GL_ATTRIBUTE_CONST
+static void
 gl_array_iterator_free (gl_oset_iterator_t *iterator 
_GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }
diff --git a/lib/gl_carray_list.c b/lib/gl_carray_list.c
index 8c2dc4e..e602516 100644
--- a/lib/gl_carray_list.c
+++ b/lib/gl_carray_list.c
@@ -680,7 +680,7 @@ gl_carray_iterator_next (gl_list_iterator_t *iterator,
     return false;
 }
 
-static void _GL_ATTRIBUTE_CONST
+static void
 gl_carray_iterator_free (gl_list_iterator_t *iterator 
_GL_ATTRIBUTE_MAYBE_UNUSED)
 {
 }




reply via email to

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