]> Savannah Git Hosting - gnulib.git/commitdiff
stdio: fix probe on mingw under gcc 5.1
authorEric Blake <eblake@redhat.com>
Wed, 20 May 2015 23:18:20 +0000 (17:18 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 26 May 2015 20:58:24 +0000 (14:58 -0600)
Per https://gcc.gnu.org/gcc-5/porting_to.html, gcc 5.1 intentionally
changed the preprocessor to emit multiple lines, rather than one
line, when expanding text that includes literal markers combined with
a macro expansion obtained from a header.  This in turn breaks the
probe for whether mingw headers support GNU-style "lld" for PRIdMAX,
as the probe text was no longer on one line.

This patch changes from grepping preprocessor output (with its
indeterminate layout due to differences in preprocessors) to instead
using a compile-time check of the length of the macro expansion.

It feels a bit gross, but the grossness is limited to mingw, which
is the only platform where using __gnu_printf__ instead of __printf__
will make a difference.

Based on a report by Suren Hajyan.

* m4/stdio_h.m4 (gl_STDIO_H): Change to compile test, to work
around new gcc preprocessor rules.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
m4/stdio_h.m4

index 960eec37dd1fafaa966e1939d41cffc31ceaf94c..a204cacabf5d3fe4e4700e198ac571368ec0c5d4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-05-26  Eric Blake  <eblake@redhat.com>
+
+       stdio: fix probe on mingw under gcc 5.1
+       * m4/stdio_h.m4 (gl_STDIO_H): Change to compile test, to work
+       around new gcc preprocessor rules.
+
 2015-05-07  Glenn Morris  <rgm@gnu.org>
 
        gitlog-to-changelog: parse "Tiny-change"
index e0c4bde1f8e5cf39d248148741f027a6d7a752c4..ffaf10c3971ea68ebfb3daecef7dee9525ebb0d8 100644 (file)
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 44
+# stdio_h.m4 serial 45
 dnl Copyright (C) 2007-2015 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -15,15 +15,20 @@ AC_DEFUN([gl_STDIO_H],
   dnl Determine whether __USE_MINGW_ANSI_STDIO makes printf and
   dnl inttypes.h behave like gnu instead of system; we must give our
   dnl printf wrapper the right attribute to match.
-  AC_CACHE_CHECK([whether inttypes macros match system or gnu printf],
+  AC_CACHE_CHECK([which flavor of printf attribute matches inttypes macros],
     [gl_cv_func_printf_attribute_flavor],
-    [AC_EGREP_CPP([findme .(ll|j)d. findme],
-      [#define __STDC_FORMAT_MACROS 1
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+       #define __STDC_FORMAT_MACROS 1
        #include <stdio.h>
        #include <inttypes.h>
-       findme PRIdMAX findme
-      ], [gl_cv_func_printf_attribute_flavor=gnu],
-      [gl_cv_func_printf_attribute_flavor=system])])
+       /* For non-mingw systems, compilation will trivially succeed.
+          For mingw, compilation will succeed for older mingw (system
+          printf, "I64d") and fail for newer mingw (gnu printf, "lld"). */
+       #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+       extern char PRIdMAX_probe[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1];
+       #endif
+      ]])], [gl_cv_func_printf_attribute_flavor=system],
+      [gl_cv_func_printf_attribute_flavor=gnu])])
   if test "$gl_cv_func_printf_attribute_flavor" = gnu; then
     AC_DEFINE([GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU], [1],
       [Define to 1 if printf and friends should be labeled with