mgorny created this revision. mgorny added a reviewer: EricWF. mgorny added a subscriber: cfe-commits.
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. https://reviews.llvm.org/D24903 Files: include/inttypes.h include/stdint.h Index: include/stdint.h =================================================================== --- /dev/null +++ include/stdint.h @@ -0,0 +1,33 @@ +// -*- C++ -*- +//===---------------------------- stdint.h --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STDINT_H +#define _LIBCPP_STDINT_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +/* C99 stdlib (e.g. glibc < 2.18) does not provide macros needed + for C++11 unless __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS + are defined +*/ +#if __cplusplus >= 201103L && !defined(__STDC_LIMIT_MACROS) +# define __STDC_LIMIT_MACROS +#endif +#if __cplusplus >= 201103L && !defined(__STDC_CONSTANT_MACROS) +# define __STDC_CONSTANT_MACROS +#endif + +#include_next <stdint.h> + +#endif // _LIBCPP_STDINT_H Index: include/inttypes.h =================================================================== --- include/inttypes.h +++ include/inttypes.h @@ -237,6 +237,13 @@ #pragma GCC system_header #endif +/* C99 stdlib (e.g. glibc < 2.18) does not provide format macros needed + for C++11 unless __STDC_FORMAT_MACROS is defined +*/ +#if __cplusplus >= 201103L && !defined(__STDC_FORMAT_MACROS) +# define __STDC_FORMAT_MACROS +#endif + #include_next <inttypes.h> #ifdef __cplusplus
Index: include/stdint.h =================================================================== --- /dev/null +++ include/stdint.h @@ -0,0 +1,33 @@ +// -*- C++ -*- +//===---------------------------- stdint.h --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STDINT_H +#define _LIBCPP_STDINT_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +/* C99 stdlib (e.g. glibc < 2.18) does not provide macros needed + for C++11 unless __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS + are defined +*/ +#if __cplusplus >= 201103L && !defined(__STDC_LIMIT_MACROS) +# define __STDC_LIMIT_MACROS +#endif +#if __cplusplus >= 201103L && !defined(__STDC_CONSTANT_MACROS) +# define __STDC_CONSTANT_MACROS +#endif + +#include_next <stdint.h> + +#endif // _LIBCPP_STDINT_H Index: include/inttypes.h =================================================================== --- include/inttypes.h +++ include/inttypes.h @@ -237,6 +237,13 @@ #pragma GCC system_header #endif +/* C99 stdlib (e.g. glibc < 2.18) does not provide format macros needed + for C++11 unless __STDC_FORMAT_MACROS is defined +*/ +#if __cplusplus >= 201103L && !defined(__STDC_FORMAT_MACROS) +# define __STDC_FORMAT_MACROS +#endif + #include_next <inttypes.h> #ifdef __cplusplus
_______________________________________________ cfe-commits mailing list [email protected] http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits