[include] Declare __STDC_*_MACROS for C++11 compat in old libc
authorMichal Gorny <mgorny@gentoo.org>
Mon, 26 Sep 2016 20:20:00 +0000 (20:20 +0000)
committerMichal Gorny <mgorny@gentoo.org>
Mon, 26 Sep 2016 20:20:00 +0000 (20:20 +0000)
commit9eddaeb5340035f1ed36940f7478999616a898f0
tree188154b9f0634e030b1dae62749db71a0a6d6f5b
parent5deb06eb43c73ded9debc59a87947a91649c94c0
[include] Declare __STDC_*_MACROS for C++11 compat in old libc

Declare __STDC_FORMAT_MACROS, __STDC_LIMIT_MACROS and
__STDC_CONSTANT_MACROS before including real inttypes.h/stdint.h when
the wrapper-header is included in C++11, in order to enable
the necessary macros in C99-compliant libc.

The C99 standard defined that the format macros in inttypes.h should be
defined by the C++ implementations only when __STDC_FORMAT_MACROS is
defined, and the limit and constant macros in stdint.h should be defined
only when __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS are defined
appropriately. Following this specification, multiple old versions of
glibc up to 2.17 do not define those macros by default for C++,
rendering the libc++ headers non-compliant to the C++11 standard.

In order to achieve the necessary compliance, __STDC_FORMAT_MACROS is
defined in wrapped inttypes.h just before including the system
inttypes.h, when C++11 or newer is used. Both __STDC_LIMIT_MACROS
and __STDC_CONSTANT_MACROS are defined in newly-wrapped stdint.h. This
fixes the C++11 compliance while preserving the current behavior for
C++03.

Differential Revision: https://reviews.llvm.org/D24903

llvm-svn: 282435
libcxx/include/inttypes.h
libcxx/include/stdint.h [new file with mode: 0644]