[libcxx-commits] [PATCH] D138512: [libc++] Add missing __has_include checks for C headers not provided by libc++

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 22 10:48:53 PST 2022


ldionne created this revision.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138512

Files:
  libcxx/include/cassert
  libcxx/include/csignal
  libcxx/include/cstdarg
  libcxx/include/ctime


Index: libcxx/include/ctime
===================================================================
--- libcxx/include/ctime
+++ libcxx/include/ctime
@@ -47,7 +47,11 @@
 
 #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>
+#endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
Index: libcxx/include/cstdarg
===================================================================
--- libcxx/include/cstdarg
+++ libcxx/include/cstdarg
@@ -33,7 +33,11 @@
 
 #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>
+#endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
Index: libcxx/include/csignal
===================================================================
--- libcxx/include/csignal
+++ libcxx/include/csignal
@@ -42,6 +42,7 @@
 #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>
 #endif
Index: libcxx/include/cassert
===================================================================
--- libcxx/include/cassert
+++ libcxx/include/cassert
@@ -18,7 +18,11 @@
 
 #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>
+#endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138512.477250.patch
Type: text/x-patch
Size: 1795 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221122/5f6b64ec/attachment.bin>


More information about the libcxx-commits mailing list