From b62fec49d73b8e054cc0f388de21279bfb3d3592 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 26 May 2015 17:26:15 -0600 Subject: [PATCH] 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 --- ChangeLog | 3 +++ lib/error.h | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e96045b6c8..6ac962272d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-05-26 Eric Blake + error: use correct printf attributes on mingw + * lib/stdio.in.h (_GL_ATTRIBUTE_SPEC_PRINTF): New define. + inttypes: force correct mingw PRIdMAX even without * modules/inttypes (Depends-on): Require extensions, so that mingw always uses GNU style inttypes. diff --git a/lib/error.h b/lib/error.h index ccffef5853..9e594ced93 100644 --- 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 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 @@ extern "C" { 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 -- 2.39.5