diff options
author | Louis Dionne <ldionne.2@gmail.com> | 2022-11-22 13:42:33 -0500 |
---|---|---|
committer | Louis Dionne <ldionne.2@gmail.com> | 2022-11-23 09:50:14 -0500 |
commit | 647ddc08f43c05131031cfe3c6114d7870f5a117 (patch) | |
tree | 5890637c2d944239d43970b75c67ec557887de9f /libcxx | |
parent | 09b8b44760423ff822b3755647a8f69ea1b8de3e (diff) | |
download | llvm-647ddc08f43c05131031cfe3c6114d7870f5a117.zip llvm-647ddc08f43c05131031cfe3c6114d7870f5a117.tar.gz llvm-647ddc08f43c05131031cfe3c6114d7870f5a117.tar.bz2 |
[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
Diffstat (limited to 'libcxx')
-rw-r--r-- | libcxx/include/cassert | 9 | ||||
-rw-r--r-- | libcxx/include/csignal | 6 | ||||
-rw-r--r-- | libcxx/include/cstdarg | 9 | ||||
-rw-r--r-- | libcxx/include/ctime | 9 |
4 files changed, 29 insertions, 4 deletions
diff --git a/libcxx/include/cassert b/libcxx/include/cassert index 28fc0b1..761f57d 100644 --- a/libcxx/include/cassert +++ b/libcxx/include/cassert @@ -18,7 +18,14 @@ Macros: #include <__assert> // all public C++ headers provide the assertion handler #include <__config> -#include <assert.h> + +// <assert.h> is not provided by libc++ +#if __has_include(<assert.h>) +# include <assert.h> +# ifdef _LIBCPP_ASSERT_H +# error "If libc++ starts defining <assert.h>, the __has_include check should move to libc++'s <assert.h>" +# endif +#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/libcxx/include/csignal b/libcxx/include/csignal index c1b58f8..cf45f50 100644 --- a/libcxx/include/csignal +++ b/libcxx/include/csignal @@ -42,8 +42,12 @@ int raise(int sig); #include <__assert> // all public C++ headers provide the assertion handler #include <__config> +// <signal.h> is not provided by libc++ #if __has_include(<signal.h>) -# include <signal.h> +# include <signal.h> +# ifdef _LIBCPP_SIGNAL_H +# error "If libc++ starts defining <signal.h>, the __has_include check should move to libc++'s <signal.h>" +# endif #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/cstdarg b/libcxx/include/cstdarg index f36ade2..3a4291f 100644 --- a/libcxx/include/cstdarg +++ b/libcxx/include/cstdarg @@ -33,7 +33,14 @@ Types: #include <__assert> // all public C++ headers provide the assertion handler #include <__config> -#include <stdarg.h> + +// <stdarg.h> is not provided by libc++ +#if __has_include(<stdarg.h>) +# include <stdarg.h> +# ifdef _LIBCPP_STDARG_H +# error "If libc++ starts defining <stdarg.h>, the __has_include check should move to libc++'s <stdarg.h>" +# endif +#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/libcxx/include/ctime b/libcxx/include/ctime index 0c6e4df..2293675 100644 --- a/libcxx/include/ctime +++ b/libcxx/include/ctime @@ -47,7 +47,14 @@ int timespec_get( struct timespec *ts, int base); // C++17 #include <__assert> // all public C++ headers provide the assertion handler #include <__config> -#include <time.h> + +// <time.h> is not provided by libc++ +#if __has_include(<time.h>) +# include <time.h> +# ifdef _LIBCPP_TIME_H +# error "If libc++ starts defining <time.h>, the __has_include check should move to libc++'s <time.h>" +# endif +#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header |