[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] mark functions with const and pure attributes
From: |
Jim Meyering |
Subject: |
Re: [PATCH] mark functions with const and pure attributes |
Date: |
Mon, 28 Nov 2011 08:16:26 +0100 |
Bruno Haible wrote:
>> --- a/lib/quotearg.c
>> +++ b/lib/quotearg.c
>> @@ -17,6 +17,11 @@
>>
>> /* Written by Paul Eggert <address@hidden> */
>>
>> +/* Without this pragma, gcc 4.7.0 20111124 mistakenly suggests that
>> + the quoting_options_from_style function might be candidate for
>> + attribute 'pure' */
>> +# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
>> +
>> #include <config.h>
>>
>> #include "quotearg.h"
>
> This pragma line should be enclosed in
>
> #if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
> #endif
Definitely.
> like it is done in
> lib/anytostr.c
> lib/poll.c
> tests/test-intprops.c
> tests/test-nl_langinfo.c
>
> Otherwise (most likely) earlier versions of GCC will warn about an unsupported
> pragma.
>
>> --- a/lib/uniwidth.in.h
>> +++ b/lib/uniwidth.in.h
>> @@ -38,7 +38,7 @@ extern "C" {
>>
>> /* Determine number of column positions required for UC. */
>> extern int
>> - uc_width (ucs4_t uc, const char *encoding);
>> + uc_width (ucs4_t uc, const char *encoding) _GL_ATTRIBUTE_PURE;
Good catch.
>> /* Determine number of column positions required for first N units
>> (or fewer if S ends before this) in S. */
>
> This header file is installed as a public header file by libunistring.
> It cannot presuppose the macro definitions of gnulib-common.m4. Therefore
> here one needs to write
>
> extern int
> uc_width (ucs4_t uc, const char *encoding)
> #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
> __attribute__ ((__pure__))
> #endif
> ;
Thanks for the speedy review!