[libc++] Improve LIBCXX_ENABLE_INCOMPLETE_FEATURES.
@tcanens pointed out the current behavior of the macro breaks the usage
pattern described in http://wg21.link/SD6
```
# if __has_include(<optional>)
# include <optional>
# if __cpp_lib_optional >= 201606
# define have_optional 1
# endif
```
To support this usage pattern the hard errror is removed. Instead the
header includes nothing but the `<version>` header.
Reviewed By: ldionne, #libc
Differential Revision: https://reviews.llvm.org/D107134
GitOrigin-RevId: d618a1cc5c3919d29ee27fa48de80bed4dcb3566
diff --git a/include/format b/include/format
index 0ec4b85..cfd851a 100644
--- a/include/format
+++ b/include/format
@@ -55,14 +55,14 @@
*/
+// Make sure all feature tests macros are always available.
+#include <version>
+// Only enable the contents of the header when libc++ was build with LIBCXX_ENABLE_INCOMPLETE_FEATURES enabled
+#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
+
#include <__config>
#include <__format/format_error.h>
#include <__format/format_parse_context.h>
-#include <version>
-
-#if defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
-# error "The Format library is not supported since libc++ has been configured with LIBCXX_ENABLE_INCOMPLETE_FEATURES disabled"
-#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -81,4 +81,6 @@
_LIBCPP_POP_MACROS
+#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
+
#endif // _LIBCPP_FORMAT
diff --git a/include/ranges b/include/ranges
index f1a3f5e..cd29aee 100644
--- a/include/ranges
+++ b/include/ranges
@@ -170,6 +170,11 @@
*/
+// Make sure all feature tests macros are always available.
+#include <version>
+// Only enable the contents of the header when libc++ was build with LIBCXX_ENABLE_INCOMPLETE_FEATURES enabled
+#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
#include <__config>
#include <__ranges/access.h>
#include <__ranges/all.h>
@@ -193,11 +198,6 @@
#include <initializer_list> // Required by the standard.
#include <iterator> // Required by the standard.
#include <type_traits>
-#include <version>
-
-#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
-# error "The Ranges library is not supported since libc++ has been configured with LIBCXX_ENABLE_INCOMPLETE_FEATURES disabled"
-#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -216,4 +216,6 @@
_LIBCPP_POP_MACROS
+#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
#endif // _LIBCPP_RANGES