]> Savannah Git Hosting - gnulib.git/commitdiff
stdint: detect good enough pre-C++11 stdint.h in C++ mode
authorPedro Alves <palves@redhat.com>
Mon, 4 Apr 2016 05:48:22 +0000 (22:48 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 4 Apr 2016 06:05:34 +0000 (23:05 -0700)
When gnulib is configured in C++ mode for a system with a working C99
implementation of stdint.h that predates C++11, gnulib ends up
substituting stdint.h anyway.  This works on most targets, but on e.g.,
64-bit MinGW, it doesn't, as gnulib's substitute assumes LP64, while
MinGW is LLP64.  Instead of trying to detect the right types, detect
good-enough-pre-C++11 stdint.h and in such case define
__STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS in config.h.
* m4/stdint.m4 (gl_STDINT_H): Always define __STDC_CONSTANT_MACROS
/ __STDC_LIMIT_MACROS while checking whether the system stdint.h
conforms to C99.  If it does, check whether it hides symbols
behind the __STDC_{CONSTANT|LIMIT}_MACROS macros.  Then if it
does, define those macros in config.h.

ChangeLog
m4/stdint.m4

index 0bdbf57406534f0e2f009506da8bf3c8449e903a..980cfaae5cea577983fb864475731307d60c01d4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2016-04-03  Pedro Alves  <palves@redhat.com>
+
+       stdint: detect good enough pre-C++11 stdint.h in C++ mode
+       When gnulib is configured in C++ mode for a system with a working C99
+       implementation of stdint.h that predates C++11, gnulib ends up
+       substituting stdint.h anyway.  This works on most targets, but on e.g.,
+       64-bit MinGW, it doesn't, as gnulib's substitute assumes LP64, while
+       MinGW is LLP64.  Instead of trying to detect the right types, detect
+       good-enough-pre-C++11 stdint.h and in such case define
+       __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS in config.h.
+       * m4/stdint.m4 (gl_STDINT_H): Always define __STDC_CONSTANT_MACROS
+       / __STDC_LIMIT_MACROS while checking whether the system stdint.h
+       conforms to C99.  If it does, check whether it hides symbols
+       behind the __STDC_{CONSTANT|LIMIT}_MACROS macros.  Then if it
+       does, define those macros in config.h.
+
 2016-04-03  Paul Eggert  <eggert@cs.ucla.edu>
 
        argp: merge changes from glibc
index 0f40ce803b7becf7f718f19cf54b6733e24bc623..0b4b9060dbbb48c599a0dc33326db10ebcde7e02 100644 (file)
@@ -1,4 +1,4 @@
-# stdint.m4 serial 43
+# stdint.m4 serial 44
 dnl Copyright (C) 2001-2016 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -70,6 +70,8 @@ AC_DEFUN_ONCE([gl_STDINT_H],
        AC_COMPILE_IFELSE([
          AC_LANG_PROGRAM([[
 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#define __STDC_CONSTANT_MACROS 1
+#define __STDC_LIMIT_MACROS 1
 #include <stdint.h>
 /* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>.  */
 #if !(defined WCHAR_MIN && defined WCHAR_MAX)
@@ -218,6 +220,8 @@ struct s {
           AC_RUN_IFELSE([
             AC_LANG_PROGRAM([[
 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#define __STDC_CONSTANT_MACROS 1
+#define __STDC_LIMIT_MACROS 1
 #include <stdint.h>
 ]
 gl_STDINT_INCLUDES
@@ -279,6 +283,29 @@ static const char *macro_values[] =
       ])
   fi
   if test "$gl_cv_header_working_stdint_h" = yes; then
+    dnl Now see whether the system <stdint.h> works without
+    dnl __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined.
+    AC_CACHE_CHECK([whether stdint.h predates C++11],
+      [gl_cv_header_stdint_predates_cxx11_h],
+      [gl_cv_header_stdint_predates_cxx11_h=yes
+       AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM([[
+#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#include <stdint.h>
+]
+gl_STDINT_INCLUDES
+[
+intmax_t im = INTMAX_MAX;
+int32_t i32 = INT32_C (0x7fffffff);
+         ]])],
+         [gl_cv_header_stdint_predates_cxx11_h=no])])
+
+    if test "$gl_cv_header_stdint_predates_cxx11_h" = yes; then
+      AC_DEFINE([__STDC_CONSTANT_MACROS], [1],
+                [Define to 1 if the system <stdint.h> predates C++11.])
+      AC_DEFINE([__STDC_LIMIT_MACROS], [1],
+                [Define to 1 if the system <stdint.h> predates C++11.])
+    fi
     STDINT_H=
   else
     dnl Check for <sys/inttypes.h>, and for