diff --git a/libcxx/include/__availability b/libcxx/include/__availability --- a/libcxx/include/__availability +++ b/libcxx/include/__availability @@ -172,6 +172,9 @@ // be avoided. // # define _LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY + // This controls the availabilty of everything inside the std::pmr namespace introduced in P0220R1. +# define _LIBCPP_AVAILABILITY_MEMORY_RESOURCE + #elif defined(__APPLE__) # define _LIBCPP_AVAILABILITY_SHARED_MUTEX \ @@ -273,6 +276,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: @@ -51,23 +51,22 @@ // [mem.res.eq] -inline _LIBCPP_HIDE_FROM_ABI bool operator==(const memory_resource& __lhs, const memory_resource& __rhs) noexcept { +_LIBCPP_AVAILABILITY_MEMORY_RESOURCE inline _LIBCPP_HIDE_FROM_ABI bool +operator==(const memory_resource& __lhs, const memory_resource& __rhs) noexcept { return &__lhs == &__rhs || __lhs.is_equal(__rhs); } -inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const memory_resource& __lhs, const memory_resource& __rhs) noexcept { +_LIBCPP_AVAILABILITY_MEMORY_RESOURCE inline _LIBCPP_HIDE_FROM_ABI bool +operator!=(const memory_resource& __lhs, const memory_resource& __rhs) noexcept { return !(__lhs == __rhs); } // [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/include/deque b/libcxx/include/deque --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -2934,7 +2934,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template -using deque = std::deque<_ValueT, polymorphic_allocator<_ValueT>>; +using deque = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::deque<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr _LIBCPP_END_NAMESPACE_STD #endif diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -1783,7 +1783,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template -using forward_list = std::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; +using forward_list = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr _LIBCPP_END_NAMESPACE_STD #endif diff --git a/libcxx/include/list b/libcxx/include/list --- a/libcxx/include/list +++ b/libcxx/include/list @@ -2366,7 +2366,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template -using list = std::list<_ValueT, polymorphic_allocator<_ValueT>>; +using list = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::list<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr _LIBCPP_END_NAMESPACE_STD #endif diff --git a/libcxx/include/map b/libcxx/include/map --- a/libcxx/include/map +++ b/libcxx/include/map @@ -2343,10 +2343,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template > -using map = std::map<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; +using map = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE + std::map<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; template > -using multimap = std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; +using multimap = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE + std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; } // namespace pmr _LIBCPP_END_NAMESPACE_STD #endif diff --git a/libcxx/include/regex b/libcxx/include/regex --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -6842,12 +6842,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template -using match_results = std::match_results<_BidirT, polymorphic_allocator>>; +using match_results = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::match_results<_BidirT, polymorphic_allocator>>; -using cmatch = match_results; -using wcmatch = match_results; -using smatch = match_results; -using wsmatch = match_results; +using cmatch = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE match_results; +using wcmatch = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE match_results; +using smatch = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE match_results; +using wsmatch = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE match_results; } // namespace pmr _LIBCPP_END_NAMESPACE_STD #endif diff --git a/libcxx/include/set b/libcxx/include/set --- a/libcxx/include/set +++ b/libcxx/include/set @@ -1588,10 +1588,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template > -using set = std::set<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; +using set = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::set<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; template > -using multiset = std::multiset<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; +using multiset = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::multiset<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; } // namespace pmr _LIBCPP_END_NAMESPACE_STD #endif diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -4678,12 +4678,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template > -using basic_string = std::basic_string<_CharT, _TraitsT, polymorphic_allocator<_CharT>>; +using basic_string = + _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::basic_string<_CharT, _TraitsT, polymorphic_allocator<_CharT>>; -using string = basic_string; -using u16string = basic_string; -using u32string = basic_string; -using wstring = basic_string; +using string = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE basic_string; +using u16string = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE basic_string; +using u32string = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE basic_string; +using wstring = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE basic_string; } // namespace pmr _LIBCPP_END_NAMESPACE_STD #endif diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -2633,11 +2633,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template , class _PredT = std::equal_to<_KeyT>> -using unordered_map = +using unordered_map = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; template , class _PredT = std::equal_to<_KeyT>> -using unordered_multimap = +using unordered_multimap = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; } // namespace pmr _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -1807,10 +1807,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template , class _PredT = std::equal_to<_KeyT>> -using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; +using unordered_set = + _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::unordered_set<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; template , class _PredT = std::equal_to<_KeyT>> -using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; +using unordered_multiset = + _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::unordered_multiset<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; } // namespace pmr _LIBCPP_END_NAMESPACE_STD #endif diff --git a/libcxx/include/vector b/libcxx/include/vector --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3272,7 +3272,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { template -using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; +using vector = _LIBCPP_AVAILABILITY_MEMORY_RESOURCE std::vector<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr _LIBCPP_END_NAMESPACE_STD #endif 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,58 @@ +//===----------------------------------------------------------------------===// +// +// 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void f() { + [[maybe_unused]] std::pmr::match_results m1; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::cmatch m2; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::wcmatch m3; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::smatch m4; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::wsmatch m5; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::deque m6; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::forward_list m7; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::list m8; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::map m9; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::multimap m10; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::set m11; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::multiset m12; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::string m13; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::wstring m14; // expected-error {{is unavailable}} + // TODO: check once alias is added + // [[maybe_unused]] std::pmr::u8string m15; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::u16string m16; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::u32string m17; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::basic_string m18; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::unordered_map m19; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::unordered_multimap m20; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::unordered_set m21; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::unordered_multiset m22; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::vector m23; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::polymorphic_allocator poly; // expected-error {{is unavailable}} + [[maybe_unused]] std::pmr::memory_resource* res = nullptr; // 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}} + (void)(*res == *res); // expected-error {{is unavailable}} +}