bug-gnulib
[Top][All Lists]
Advanced

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

"localename" functions suggest pure/const attribute


From: Assaf Gordon
Subject: "localename" functions suggest pure/const attribute
Date: Wed, 09 Jul 2014 20:29:05 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

Hello,


Relating to a coreutil patch I previously sent, I'm using gnulib's "localename" 
module.
Compiling it triggers two warnings (and errors with -Werror) about functions 
being candidates for pure/const attributes.
I couldn't trigger it directly with gnulib, but it's reproducible with 
"coreutils":

====
# Start with fresh coreutils
$ git clone git://git.sv.gnu.org/coreutils.git
$ cd coreutils

# add "localename" to list of gnulib modules:
$ sed -i '/lstat/ilocalename' bootstrap.conf

# build
$ ./bootstrap && ./configure && make
====

Compilation will stop with:
====
  CC       lib/localename.o
lib/localename.c: In function 'string_hash':
lib/localename.c:2519:1: error: function might be candidate for attribute 
'pure' if it is known to return normally [-Werror=suggest-attribute=pure]
 string_hash (const void *x)
 ^
cc1: all warnings being treated as errors
make[2]: *** [lib/localename.o] Error 1
make[2]: Leaving directory `/home/gordon/temp/temp/coreutils'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/gordon/temp/temp/coreutils'
make: *** [all] Error 2
====

# Fix by adding 'pure', leads to another error:
====
$ sed -i 2519i_GL_ATTRIBUTE_PURE lib/localename.c
$ make

make[2]: Entering directory `/home/gordon/temp/temp/coreutils'
  CC       lib/localename.o
lib/localename.c: In function 'gl_locale_name_default':
lib/localename.c:2741:1: error: function might be candidate for attribute 
'const' [-Werror=suggest-attribute=const]
 gl_locale_name_default (void)
 ^
cc1: all warnings being treated as errors
make[2]: *** [lib/localename.o] Error 1
====

# Fix by adding 'const', compilation completes.
$ sed -i 2741i_GL_ATTRIBUTE_CONST lib/localename.c
$ make
====

The first warning (for "string_hash") seems simple enough to add "PURE".
The second (for "gl_locale_name_default") is trickier because it's only "CONST" 
in certain systems.

The following patch could perhaps address these issues:
====
--- gnulib/lib/localename.c     2014-07-09 20:04:02.005513562 -0400
+++ lib/localename.c    2014-07-09 20:18:28.889505295 -0400
@@ -2516,6 +2516,7 @@ gl_locale_name_from_win32_LCID (LCID lci
    the method described by Bruno Haible.
    See http://www.haible.de/bruno/hashfunc.html.  */
 static size_t
+_GL_ATTRIBUTE_PURE
 string_hash (const void *x)
 {
   const char *s = (const char *) x;
@@ -2737,6 +2738,9 @@ gl_locale_name_environ (int category, co
 }
const char *
+#if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined 
WINDOWS_NATIVE || defined __CYGWIN__)
+_GL_ATTRIBUTE_CONST
+#endif
 gl_locale_name_default (void)
 {
   /* POSIX:2001 says:
====


Regards,
 - gordon






reply via email to

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