Harald Maier wrote:
They __THROW and __nonnull are defined in „getopt_cdefs.h“.

Thanks, I think I see the problem. Either the compiler or some macOS header does "#define __nonnull _Nonnull", and this collides with glibc's use of __nonnull. Presumably Clang uses _Nonnull as a type qualifier and some Clang headers use __nonnull as an alias for _Nonnull.

Please try the attached patch against Emacs master. If it works I plan to install it into Emacs and propagate it into Gnulib.
diff --git a/lib/getopt.in.h b/lib/getopt.in.h
index 91e086c..900b54d 100644
--- a/lib/getopt.in.h
+++ b/lib/getopt.in.h
@@ -52,6 +52,8 @@
 # endif
 #endif
 
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
 #include <getopt_cdefs.h>
 #include <getopt_pfx_core.h>
 #include <getopt_pfx_ext.h>
diff --git a/lib/getopt_core.h b/lib/getopt_core.h
index d6ef8a6..f543024 100644
--- a/lib/getopt_core.h
+++ b/lib/getopt_core.h
@@ -88,8 +88,12 @@ extern int optopt;
    enabled, the argv array (not the strings it points to) must be
    writable.  */
 
+#ifndef _GL_ARG_NONNULL
+# define _GL_ARG_NONNULL __nonnull
+#endif
+
 extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
-       __THROW __nonnull ((2, 3));
+       __THROW _GL_ARG_NONNULL ((2, 3));
 
 __END_DECLS
 
diff --git a/lib/getopt_ext.h b/lib/getopt_ext.h
index 79b7a67..fc99e3a 100644
--- a/lib/getopt_ext.h
+++ b/lib/getopt_ext.h
@@ -63,14 +63,18 @@ struct option
 #define required_argument	1
 #define optional_argument	2
 
+#ifndef _GL_ARG_NONNULL
+# define _GL_ARG_NONNULL __nonnull
+#endif
+
 extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
 			const char *__shortopts,
 		        const struct option *__longopts, int *__longind)
-       __THROW __nonnull ((2, 3));
+       __THROW _GL_ARG_NONNULL ((2, 3));
 extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
 			     const char *__shortopts,
 		             const struct option *__longopts, int *__longind)
-       __THROW __nonnull ((2, 3));
+       __THROW _GL_ARG_NONNULL ((2, 3));
 
 __END_DECLS
 
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 38adf2a..d25ea0a 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -1527,6 +1527,7 @@ getopt.h: getopt.in.h $(top_builddir)/config.status
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
 	      -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
 	      < $(srcdir)/getopt.in.h; \
 	} > $@-t && \
 	mv -f $@-t $@

Reply via email to