[libcxx-commits] [libcxx] 647ddc0 - [libc++] Add missing __has_include checks for C headers not provided by libc++
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 23 06:50:28 PST 2022
Author: Louis Dionne
Date: 2022-11-23T09:50:14-05:00
New Revision: 647ddc08f43c05131031cfe3c6114d7870f5a117
URL: https://github.com/llvm/llvm-project/commit/647ddc08f43c05131031cfe3c6114d7870f5a117
DIFF: https://github.com/llvm/llvm-project/commit/647ddc08f43c05131031cfe3c6114d7870f5a117.diff
LOG: [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
Added:
Modified:
libcxx/include/cassert
libcxx/include/csignal
libcxx/include/cstdarg
libcxx/include/ctime
Removed:
################################################################################
diff --git a/libcxx/include/cassert b/libcxx/include/cassert
index 28fc0b10e9f4..761f57dee1db 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 c1b58f818b62..cf45f507535e 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 f36ade202b7a..3a4291f4584a 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 0c6e4dfd6f98..2293675b4941 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
More information about the libcxx-commits
mailing list