[PATCH] inttypes, stdint: add C++11 support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


This proposed gnulib patch follows up on a thread in the autoconf
mailing list rooted at
<http://lists.gnu.org/archive/html/autoconf/2011-12/msg00002.html>.
This text below was computed with "diff -w" to avoid spurious whitespace
changes; the full (compressed) patch is attached.

diff --git a/ChangeLog b/ChangeLog
index 1a1fccb..bdc9919 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2011-12-07  Paul Eggert  <eggert@xxxxxxxxxxx>
+
+	inttypes, stdint: add C++11 support
+	C++11 says there's no need to define __STDC_CONSTANT_MACROS etc.
+	when including inttypes.h and stdint.h.  Support this change to
+	the standard.
+	* lib/inttypes.in.h (__STDC_FORMAT_MACROS) [! __cplusplus]:
+	Define if not defined already, for the benefit of pre-C++11 hosts.
+	Define the standard format macros (e.g., PRId8) always.
+	* lib/stdint.in.h (__STDC_CONSTANT_MACROS, __STDC_LIMIT_MACROS):
+	Likewise, if __cpluspus.  Define the standard constant and limit
+	macros (e.g., INT8_C, INT8_MAX) always.
+	* m4/inttypes.m4 (gl_INTTYPES_INCOMPLETE): Do not define
+	GL_TRIGGER_STDC_LIMIT_MACROS or __STDC_LIMIT_MACROS; no longer needed.
+	* m4/stdint.m4 (gl_STDINT_H): Update comments about these macros.
+	* tests/test-inttypes.c (__STDC_LIMIT_MACROS, __STDC_CONSTANT_MACROS)
+	(__STDC_FORMAT_MACROS): Do not define, since we assume C++11 API now.
+	* tests/test-stdint.c (__STDC_LIMIT_MACROS, __STDC_CONSTANT_MACROS):
+	Likewise.
+
 2011-12-04  Bruno Haible  <bruno@xxxxxxxxx>
 
 	sethostname: Port to Windows platforms.
diff --git a/lib/inttypes.in.h b/lib/inttypes.in.h
index 7abf394..f7c489a 100644
--- a/lib/inttypes.in.h
+++ b/lib/inttypes.in.h
@@ -31,6 +31,12 @@
    The include_next requires a split double-inclusion guard.  */
 #if ! defined INTTYPES_H || defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
 # if @HAVE_INTTYPES_H@
+
+   /* Some pre-C++11 <stdint.h> implementations need this.  */
+#  if defined __cplusplus && ! defined __STDC_FORMAT_MACROS
+#   define __STDC_FORMAT_MACROS 1
+#  endif
+
 #  @INCLUDE_NEXT@ @NEXT_INTTYPES_H@
 # endif
 #endif
@@ -56,8 +62,6 @@
 
 /* 7.8.1 Macros for format specifiers */
 
-#if ! defined __cplusplus || defined __STDC_FORMAT_MACROS
-
 # if defined _TNS_R_TARGET
    /* Tandem NonStop R series and compatible platforms released before
       July 2005 support %Ld but not %lld.  */
@@ -1038,8 +1042,6 @@
 #  endif
 # endif
 
-#endif
-
 /* 7.8.2 Functions for greatest-width integer types */
 
 #ifdef __cplusplus
diff --git a/lib/stdint.in.h b/lib/stdint.in.h
index aa5ca91..7769582 100644
--- a/lib/stdint.in.h
+++ b/lib/stdint.in.h
@@ -49,6 +49,17 @@
       diagnostics.  */
 #  define __STDINT_H__
 # endif
+
+  /* Some pre-C++11 <stdint.h> implementations need this.  */
+# ifdef __cplusplus
+#  ifndef __STDC_CONSTANT_MACROS
+#   define __STDC_CONSTANT_MACROS 1
+#  endif
+#  ifndef __STDC_LIMIT_MACROS
+#   define __STDC_LIMIT_MACROS 1
+#  endif
+# endif
+
   /* Other systems may have an incomplete or buggy <stdint.h>.
      Include it before <inttypes.h>, since any "#include <stdint.h>"
      in <inttypes.h> would reinclude us, skipping our contents because
@@ -313,8 +324,6 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
 
 /* 7.18.2. Limits of specified-width integer types */
 
-#if ! defined __cplusplus || defined __STDC_LIMIT_MACROS
-
 /* 7.18.2.1. Limits of exact-width integer types */
 
 /* Here we assume a standard architecture where the hardware integer
@@ -534,12 +543,8 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
 #define WINT_MAX  \
    _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
 
-#endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */
-
 /* 7.18.4. Macros for integer constants */
 
-#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
-
 /* 7.18.4.1. Macros for minimum-width integer constants */
 /* According to ISO C 99 Technical Corrigendum 1 */
 
@@ -600,7 +605,5 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
 # endif
 #endif
 
-#endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */
-
 #endif /* _@GUARD_PREFIX@_STDINT_H */
 #endif /* !defined _@GUARD_PREFIX@_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */
diff --git a/m4/inttypes.m4 b/m4/inttypes.m4
index cc027a4..2691fec 100644
--- a/m4/inttypes.m4
+++ b/m4/inttypes.m4
@@ -1,4 +1,4 @@
-# inttypes.m4 serial 24
+# inttypes.m4 serial 25
 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -24,22 +24,6 @@ AC_DEFUN_ONCE([gl_INTTYPES_INCOMPLETE],
 
   AC_REQUIRE([gl_MULTIARCH])
 
-  dnl Ensure that <stdint.h> defines the limit macros, since gnulib's
-  dnl <inttypes.h> relies on them.  This macro is only needed when a
-  dnl C++ compiler is in use; it has no effect for a C compiler.
-  dnl Also be careful to define __STDC_LIMIT_MACROS only when gnulib's
-  dnl <inttypes.h> is going to be created, and to avoid redefinition warnings
-  dnl if the __STDC_LIMIT_MACROS is already defined through the CPPFLAGS.
-  AC_DEFINE([GL_TRIGGER_STDC_LIMIT_MACROS], [1],
-    [Define to make the limit macros in <stdint.h> visible.])
-  AH_VERBATIM([__STDC_LIMIT_MACROS_ZZZ],
-[/* Ensure that <stdint.h> defines the limit macros, since gnulib's
-   <inttypes.h> relies on them.  */
-#if defined __cplusplus && !defined __STDC_LIMIT_MACROS && GL_TRIGGER_STDC_LIMIT_MACROS
-# define __STDC_LIMIT_MACROS 1
-#endif
-])
-
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use.
   gl_WARN_ON_USE_PREPARE([[#include <inttypes.h>
diff --git a/m4/stdint.m4 b/m4/stdint.m4
index 092161c..cfad016 100644
--- a/m4/stdint.m4
+++ b/m4/stdint.m4
@@ -1,4 +1,4 @@
-# stdint.m4 serial 41
+# stdint.m4 serial 42
 dnl Copyright (C) 2001-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -69,8 +69,8 @@ AC_DEFUN_ONCE([gl_STDINT_H],
       [gl_cv_header_working_stdint_h=no
        AC_COMPILE_IFELSE([
          AC_LANG_PROGRAM([[
-#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
-#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */
+#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ before C++11 */
+#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ before C++11 */
 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
 #include <stdint.h>
 /* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>.  */
@@ -219,8 +219,8 @@ struct s {
           dnl This detects a bug on HP-UX 11.23/ia64.
           AC_RUN_IFELSE([
             AC_LANG_PROGRAM([[
-#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
-#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */
+#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ before C++11 */
+#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ before C++11 */
 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
 #include <stdint.h>
 ]
diff --git a/tests/test-inttypes.c b/tests/test-inttypes.c
index 5bf952c..b4b982d 100644
--- a/tests/test-inttypes.c
+++ b/tests/test-inttypes.c
@@ -18,9 +18,6 @@
 
 #include <config.h>
 
-#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
-#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */
-#define __STDC_FORMAT_MACROS 1 /* to make it work also in C++ mode */
 #include <inttypes.h>
 
 #include <stddef.h>
diff --git a/tests/test-stdint.c b/tests/test-stdint.c
index f606cc3..0341652 100644
--- a/tests/test-stdint.c
+++ b/tests/test-stdint.c
@@ -21,8 +21,6 @@
 /* Whether to enable pedantic checks. */
 #define DO_PEDANTIC 0
 
-#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
-#define __STDC_CONSTANT_MACROS 1 /* likewise */
 #include <stdint.h>
 
 #include "verify.h"

Attachment: patch.gz
Description: GNU Zip compressed data

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
https://lists.gnu.org/mailman/listinfo/autoconf

[GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [USB]     [Samba]

Add to Google Powered by Linux