diff --git a/libcxx/include/__availability b/libcxx/include/__availability --- a/libcxx/include/__availability +++ b/libcxx/include/__availability @@ -172,6 +172,8 @@ // be avoided. // # define _LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY +# define _LIBCPP_AVAILABILITY_MEMORY_RESOURCE + #elif defined(__APPLE__) # define _LIBCPP_AVAILABILITY_SHARED_MUTEX \ @@ -273,6 +275,8 @@ # define _LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY +# define _LIBCPP_AVAILABILITY_MEMORY_RESOURCE __attribute__((__unavailable__)) + #else // ...New vendors can add availability markup here... diff --git a/libcxx/include/__memory_resource/memory_resource.h b/libcxx/include/__memory_resource/memory_resource.h --- a/libcxx/include/__memory_resource/memory_resource.h +++ b/libcxx/include/__memory_resource/memory_resource.h @@ -26,7 +26,7 @@ _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wweak-vtables") // TODO: move destructor into the dylib -class _LIBCPP_TYPE_VIS memory_resource { +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_MEMORY_RESOURCE memory_resource { static const size_t __max_align = alignof(max_align_t); public: @@ -61,13 +61,10 @@ // [mem.res.global] -_LIBCPP_FUNC_VIS memory_resource* get_default_resource() noexcept; - -_LIBCPP_FUNC_VIS memory_resource* set_default_resource(memory_resource*) noexcept; - -_LIBCPP_FUNC_VIS memory_resource* new_delete_resource() noexcept; - -_LIBCPP_FUNC_VIS memory_resource* null_memory_resource() noexcept; +_LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource* get_default_resource() noexcept; +_LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource* set_default_resource(memory_resource*) noexcept; +_LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource* new_delete_resource() noexcept; +_LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource* null_memory_resource() noexcept; } // namespace pmr diff --git a/libcxx/include/__memory_resource/monotonic_buffer_resource.h b/libcxx/include/__memory_resource/monotonic_buffer_resource.h --- a/libcxx/include/__memory_resource/monotonic_buffer_resource.h +++ b/libcxx/include/__memory_resource/monotonic_buffer_resource.h @@ -26,7 +26,7 @@ // [mem.res.monotonic.buffer] -class _LIBCPP_TYPE_VIS monotonic_buffer_resource : public memory_resource { +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_MEMORY_RESOURCE monotonic_buffer_resource : public memory_resource { static const size_t __default_buffer_capacity = 1024; static const size_t __default_buffer_alignment = 16; diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -34,7 +34,7 @@ // [mem.poly.allocator.class] template -class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_MEMORY_RESOURCE polymorphic_allocator { public: using value_type = _ValueType; diff --git a/libcxx/include/__memory_resource/synchronized_pool_resource.h b/libcxx/include/__memory_resource/synchronized_pool_resource.h --- a/libcxx/include/__memory_resource/synchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/synchronized_pool_resource.h @@ -30,7 +30,7 @@ // [mem.res.pool.overview] -class _LIBCPP_TYPE_VIS synchronized_pool_resource : public memory_resource { +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_MEMORY_RESOURCE synchronized_pool_resource : public memory_resource { public: _LIBCPP_HIDE_FROM_ABI synchronized_pool_resource(const pool_options& __opts, memory_resource* __upstream) : __unsync_(__opts, __upstream) {} diff --git a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h --- a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h @@ -27,7 +27,7 @@ // [mem.res.pool.overview] -class _LIBCPP_TYPE_VIS unsynchronized_pool_resource : public memory_resource { +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_MEMORY_RESOURCE unsynchronized_pool_resource : public memory_resource { class __fixed_pool; class __adhoc_pool { diff --git a/libcxx/test/libcxx/mem/mem.res/availability.verify.cpp b/libcxx/test/libcxx/mem/mem.res/availability.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/mem/mem.res/availability.verify.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// REQUIRES: use_system_cxx_lib && (target={{.+}}-apple-macosx10.{{9|10|11|12|13|14|15}} || target={{.+}}-apple-macosx{{11.0|12.0}}) + +#include + +void f() { + [[maybe_unused]] std::pmr::polymorphic_allocator poly; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::memory_resource* res; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::synchronized_pool_resource r1; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::monotonic_buffer_resource r2; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::unsynchronized_pool_resource r3; // expected-error {{is unavailable}} + (void)std::pmr::get_default_resource(); // expected-error {{is unavailable}} + (void)std::pmr::set_default_resource(nullptr); // expected-error {{is unavailable}} + (void)std::pmr::new_delete_resource(); // expected-error {{is unavailable}} + (void)std::pmr::null_memory_resource(); // expected-error {{is unavailable}} +}