changeset 17987:31690eec8a47

error: use correct printf attributes on mingw Now that we always turn on __USE_MINGW_ANSI_STDIO when extensions are in use, we need to replicate the same logic in error.h as we have in stdio.h, for selecting the correct format string that will squelch gcc -Wformat=2 warnings. Reported by Assaf Gordon. * lib/stdio.in.h (_GL_ATTRIBUTE_SPEC_PRINTF): New define. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Tue, 26 May 2015 17:26:15 -0600
parents 1beb80b43852
children d8e83ced2c8e
files ChangeLog lib/error.h
diffstat 2 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2015-05-26  Eric Blake  <eblake@redhat.com>
 
+	error: use correct printf attributes on mingw
+	* lib/stdio.in.h (_GL_ATTRIBUTE_SPEC_PRINTF): New define.
+
 	inttypes: force correct mingw PRIdMAX even without <stdio.h>
 	* modules/inttypes (Depends-on): Require extensions, so that mingw
 	always uses GNU style inttypes.
--- a/lib/error.h
+++ b/lib/error.h
@@ -31,6 +31,17 @@
 # define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
 #endif
 
+/* On mingw, the flavor of printf depends on whether the extensions module
+ * is in use; the check for <stdio.h> determines the witness macro.  */
+#ifndef _GL_ATTRIBUTE_SPEC_PRINTF
+# if GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU && \
+  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+#  define _GL_ATTRIBUTE_SPEC_PRINTF __gnu_printf__
+# else
+#  define _GL_ATTRIBUTE_SPEC_PRINTF __printf__
+# endif
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -40,11 +51,11 @@
    If STATUS is nonzero, terminate the program with 'exit (STATUS)'.  */
 
 extern void error (int __status, int __errnum, const char *__format, ...)
-     _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
+     _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF, 3, 4));
 
 extern void error_at_line (int __status, int __errnum, const char *__fname,
                            unsigned int __lineno, const char *__format, ...)
-     _GL_ATTRIBUTE_FORMAT ((__printf__, 5, 6));
+     _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF, 5, 6));
 
 /* If NULL, error will flush stdout, then print on stderr the program
    name, a colon and a space.  Otherwise, error will call this