[libc++][RFC] Always define internal feature test macros (#89178)
Currently, the library-internal feature test macros are only defined if
the feature is not available, and always have the prefix
`_LIBCPP_HAS_NO_`. This patch changes that, so that they are always
defined and have the prefix `_LIBCPP_HAS_` instead. This changes the
canonical use of these macros to `#if _LIBCPP_HAS_FEATURE`, which means
that using an undefined macro (e.g. due to a missing include) is
diagnosed now. While this is rather unlikely currently, a similar change
in `<__configuration/availability.h>` caught a few bugs. This also
improves readability, since it removes the double-negation of `#ifndef
_LIBCPP_HAS_NO_FEATURE`.
The current patch only touches the macros defined in `<__config>`. If
people are happy with this approach, I'll make a follow-up PR to also
change the macros defined in `<__config_site>`.
diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp
index d2ff350..299f810 100644
--- a/libcxx/src/memory_resource.cpp
+++ b/libcxx/src/memory_resource.cpp
@@ -9,7 +9,7 @@
#include <memory>
#include <memory_resource>
-#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
+#if _LIBCPP_HAS_ATOMIC_HEADER
# include <atomic>
#elif !defined(_LIBCPP_HAS_NO_THREADS)
# include <mutex>
@@ -28,7 +28,7 @@
// new_delete_resource()
-#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
static bool is_aligned_to(void* ptr, size_t align) {
void* p2 = ptr;
size_t space = 1;
@@ -39,7 +39,7 @@
class _LIBCPP_EXPORTED_FROM_ABI __new_delete_memory_resource_imp : public memory_resource {
void* do_allocate(size_t bytes, size_t align) override {
-#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+#if _LIBCPP_HAS_ALIGNED_ALLOCATION
return std::__libcpp_allocate(bytes, align);
#else
if (bytes == 0)
@@ -91,7 +91,7 @@
// default_memory_resource()
static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept {
-#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
+#if _LIBCPP_HAS_ATOMIC_HEADER
static constinit atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
if (set) {
new_res = new_res ? new_res : new_delete_resource();