Skip to content

Commit 647ddc0

Browse files
committed
[libc++] Add missing __has_include checks for C headers not provided by libc++
This makes the library consistent in how it handles C library headers. For C headers provided by libc++, we unconditionally include <foo.h> from <cfoo>, and then <foo.h> conditionally include_next <foo.h>. For headers not provided by libc++, <cfoo> conditionally includes the system's <foo.h> directly. Differential Revision: https://reviews.llvm.org/D138512
1 parent 09b8b44 commit 647ddc0

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

libcxx/include/cassert

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ Macros:
1818

1919
#include <__assert> // all public C++ headers provide the assertion handler
2020
#include <__config>
21-
#include <assert.h>
21+
22+
// <assert.h> is not provided by libc++
23+
#if __has_include(<assert.h>)
24+
# include <assert.h>
25+
# ifdef _LIBCPP_ASSERT_H
26+
# error "If libc++ starts defining <assert.h>, the __has_include check should move to libc++'s <assert.h>"
27+
# endif
28+
#endif
2229

2330
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2431
# pragma GCC system_header

libcxx/include/csignal

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ int raise(int sig);
4242
#include <__assert> // all public C++ headers provide the assertion handler
4343
#include <__config>
4444

45+
// <signal.h> is not provided by libc++
4546
#if __has_include(<signal.h>)
46-
# include <signal.h>
47+
# include <signal.h>
48+
# ifdef _LIBCPP_SIGNAL_H
49+
# error "If libc++ starts defining <signal.h>, the __has_include check should move to libc++'s <signal.h>"
50+
# endif
4751
#endif
4852

4953
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

libcxx/include/cstdarg

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ Types:
3333

3434
#include <__assert> // all public C++ headers provide the assertion handler
3535
#include <__config>
36-
#include <stdarg.h>
36+
37+
// <stdarg.h> is not provided by libc++
38+
#if __has_include(<stdarg.h>)
39+
# include <stdarg.h>
40+
# ifdef _LIBCPP_STDARG_H
41+
# error "If libc++ starts defining <stdarg.h>, the __has_include check should move to libc++'s <stdarg.h>"
42+
# endif
43+
#endif
3744

3845
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3946
# pragma GCC system_header

libcxx/include/ctime

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ int timespec_get( struct timespec *ts, int base); // C++17
4747

4848
#include <__assert> // all public C++ headers provide the assertion handler
4949
#include <__config>
50-
#include <time.h>
50+
51+
// <time.h> is not provided by libc++
52+
#if __has_include(<time.h>)
53+
# include <time.h>
54+
# ifdef _LIBCPP_TIME_H
55+
# error "If libc++ starts defining <time.h>, the __has_include check should move to libc++'s <time.h>"
56+
# endif
57+
#endif
5158

5259
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5360
# pragma GCC system_header

0 commit comments

Comments
 (0)