[PATCH] D24921: [PATCH] [Headers] Fix inttypes.h macros visibility in C++ with C99-compliant libc

Michał Górny via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 26 08:54:08 PDT 2016

mgorny created this revision.
mgorny added a reviewer: rsmith.
mgorny added a subscriber: cfe-commits.

Define `__STDC_FORMAT_MACROS` in order to enable all macros defined by inttypes.h in C++ mode, as was required by the C99 standard and was enforced by multiple old glibc versions. This extends the fix from r179419 that covered only macros defined by stdint.h but not those in inttypes.h.



Index: lib/Headers/inttypes.h
--- lib/Headers/inttypes.h
+++ lib/Headers/inttypes.h
@@ -27,8 +27,35 @@
 #error MSVC does not have inttypes.h prior to Visual Studio 2013
+// C99 7.8.1 Macros for format specifiers
+//  Footnote 191: C++ implementations should define these macros only when
+//  __STDC_FORMAT_MACROS is defined before <inttypes.h> is included.
+// C++11 [c.files]p3:
+//  The macros defined by <cinttypes> are provided unconditionally.
+//  In particular, the symbol __STDC_FORMAT_MACROS (mentioned
+//  in footnote 182 of the C standard) plays no role in C++.
+// C11 removed the problematic footnotes.
+// Work around this inconsistency by always defining those macros in C++ mode,
+// so that a C library implementation which follows the C99 standard can be
+// used in C++.
+# if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS)
+# endif
 #include_next <inttypes.h>
+# endif
 #if defined(_MSC_VER) && _MSC_VER < 1900
 /* MSVC headers define int32_t as int, but PRIx32 as "lx" instead of "x".
  * This triggers format warnings, so fix it up here. */

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24921.72499.patch
Type: text/x-patch
Size: 1386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160926/727f931f/attachment.bin>

More information about the cfe-commits mailing list