]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
getopt: merge _GL_UNUSED annotations from gnulib
authorZack Weinberg <zackw@panix.com>
Mon, 3 Apr 2017 12:45:41 +0000 (08:45 -0400)
committerZack Weinberg <zackw@panix.com>
Fri, 7 Apr 2017 11:52:29 +0000 (07:52 -0400)
gnulib now has annotations on at least some functions to cater to
compilation with -Wunused-parameter.  In order to follow suit cleanly,
I've added to libc-symbols.h some of the _GL_* macros that
gnulib-common.m4 puts into config.h.  (I don't think they belong in
sys/cdefs.h, at least not without further thought.)

At this point all gnulib-side changes to getopt.c have been merged.

* include/libc-symbols.h: For gnulib compatibility, define
_GL_UNUSED, _GL_UNUSED_LABEL, _GL_ATTRIBUTE_PURE, and
_GL_ATTRIBUTE_CONST.
* posix/getopt.c (_getopt_initialize): Mark argc and argv
parameters with _GL_UNUSED.

ChangeLog
include/libc-symbols.h
posix/getopt.c

index 4b8371a148052bd31a1ed42d3330c8e2cc18fca4..7c0f6e9446847c9099e6a0704f5b66a186005c11 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2017-04-07  Zack Weinberg  <zackw@panix.com>
 
+       * include/libc-symbols.h: For gnulib compatibility, define
+       _GL_UNUSED, _GL_UNUSED_LABEL, _GL_ATTRIBUTE_PURE, and
+       _GL_ATTRIBUTE_CONST.
+       * posix/getopt.c (_getopt_initialize): Mark argc and argv
+       parameters with _GL_UNUSED.
+
        * posix/getopt.c: When used standalone, define __libc_use_alloca
        as always false and alloca to abort if called.
        (process_long_option): Rewrite handling of ambiguous long options
index 0783ade0b34c8d4e10d6a59614a36fb15df7990d..18f26b2e61af72dcdaed5d8f524d4845d844f311 100644 (file)
@@ -892,5 +892,48 @@ for linking")
 #else
 # define inhibit_loop_to_libcall
 #endif
+\f
+/* These macros facilitate sharing source files with gnulib.
+
+   They are here instead of sys/cdefs.h because they should not be
+   used in public header files.
+
+   Their definitions should be kept consistent with the definitions in
+   gnulib-common.m4, but it is not necessary to cater to old non-GCC
+   compilers, since they will only be used while building glibc itself.
+   (Note that _GNUC_PREREQ cannot be used in this file.)  */
+
+/* Define as a marker that can be attached to declarations that might not
+    be used.  This helps to reduce warnings, such as from
+    GCC -Wunused-parameter.  */
+#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_UNUSED __attribute__ ((__unused__))
+#else
+# define _GL_UNUSED
+#endif
+
+/* gcc supports the "unused" attribute on possibly unused labels, and
+   g++ has since version 4.5.  Note to support C++ as well as C,
+   _GL_UNUSED_LABEL should be used with a trailing ;  */
+#if !defined __cplusplus || __GNUC__ > 4 \
+    || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+# define _GL_UNUSED_LABEL _GL_UNUSED
+#else
+# define _GL_UNUSED_LABEL
+#endif
+
+/* The __pure__ attribute was added in gcc 2.96.  */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
+#else
+# define _GL_ATTRIBUTE_PURE /* empty */
+#endif
+
+/* The __const__ attribute was added in gcc 2.95.  */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
+# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
+#else
+# define _GL_ATTRIBUTE_CONST /* empty */
+#endif
 
 #endif /* libc-symbols.h */
index 79c81ae2f13446b43d1e3cb2a874b94646a36f05..6671787b6fc4d20bf9e94038c9e217b0c411abaf 100644 (file)
@@ -379,7 +379,8 @@ process_long_option (int argc, char **argv, const char *optstring,
 /* Initialize internal data upon the first call to getopt.  */
 
 static const char *
-_getopt_initialize (int argc, char **argv, const char *optstring,
+_getopt_initialize (int argc _GL_UNUSED,
+                   char **argv _GL_UNUSED, const char *optstring,
                    struct _getopt_data *d, int posixly_correct)
 {
   /* Start processing options with ARGV-element 1 (since ARGV-element 0