bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] hash: pacify gcc -Wsuggest-attribute=const


From: Bruno Haible
Subject: Re: [PATCH] hash: pacify gcc -Wsuggest-attribute=const
Date: Fri, 19 May 2023 13:03:30 +0200

Hi Pádraig,

> diff --git a/lib/hash.c b/lib/hash.c
> index 918aa0d1c3..332cca6df9 100644
> --- a/lib/hash.c
> +++ b/lib/hash.c
> @@ -492,7 +492,7 @@ check_tuning (Hash_table *table)
>     TUNING, or return 0 if there is no possible way to allocate that
>     many entries.  */
>  
> -static size_t _GL_ATTRIBUTE_PURE
> +static size_t _GL_ATTRIBUTE_CONST
>  compute_bucket_size (size_t candidate, const Hash_tuning *tuning)
>  {
>    if (!tuning->is_n_buckets)
> 

This looks wrong. Per the definition of the 'const' attribute [1]
  "The const attribute prohibits a function from reading objects that
   affect its return value between successive invocations. However,
   functions declared with the attribute can safely read objects that
   do not change their return value, such as non-volatile constants."
In this function's body, testing tuning->is_n_buckets affects the
return value.

Bruno

[1] 
https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Common-Function-Attributes.html






reply via email to

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