1243da90eSArthur O'Dwyer //===----------------------------------------------------------------------===//
2243da90eSArthur O'Dwyer //
3243da90eSArthur O'Dwyer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4243da90eSArthur O'Dwyer // See https://llvm.org/LICENSE.txt for license information.
5243da90eSArthur O'Dwyer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6243da90eSArthur O'Dwyer //
7243da90eSArthur O'Dwyer //===----------------------------------------------------------------------===//
8243da90eSArthur O'Dwyer
9243da90eSArthur O'Dwyer // UNSUPPORTED: c++03, c++11, c++14
10*2da049a1SLouis Dionne // TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed
11*2da049a1SLouis Dionne // UNSUPPORTED: availability-pmr-missing
12243da90eSArthur O'Dwyer
13243da90eSArthur O'Dwyer // <string>
14243da90eSArthur O'Dwyer
15243da90eSArthur O'Dwyer // namespace std::pmr {
16243da90eSArthur O'Dwyer // template <class Char, class Traits = ...>
17243da90eSArthur O'Dwyer // using basic_string =
18243da90eSArthur O'Dwyer // ::std::basic_string<Char, Traits, polymorphic_allocator<Char>>
19243da90eSArthur O'Dwyer //
20243da90eSArthur O'Dwyer // typedef ... string
21243da90eSArthur O'Dwyer // typedef ... u16string
22243da90eSArthur O'Dwyer // typedef ... u32string
23243da90eSArthur O'Dwyer // typedef ... wstring
24243da90eSArthur O'Dwyer //
25243da90eSArthur O'Dwyer // } // namespace std::pmr
26243da90eSArthur O'Dwyer
27243da90eSArthur O'Dwyer #include <string>
28243da90eSArthur O'Dwyer #include <cassert>
29243da90eSArthur O'Dwyer #include <memory_resource>
30243da90eSArthur O'Dwyer #include <type_traits>
31243da90eSArthur O'Dwyer
32243da90eSArthur O'Dwyer #include "constexpr_char_traits.h"
33627465cfSNikolas Klauser #include "test_macros.h"
34243da90eSArthur O'Dwyer
35243da90eSArthur O'Dwyer template <class Char, class PmrTypedef>
test_string_typedef()36243da90eSArthur O'Dwyer void test_string_typedef() {
37243da90eSArthur O'Dwyer using StdStr = std::basic_string<Char, std::char_traits<Char>, std::pmr::polymorphic_allocator<Char>>;
38243da90eSArthur O'Dwyer using PmrStr = std::pmr::basic_string<Char>;
39243da90eSArthur O'Dwyer static_assert(std::is_same<StdStr, PmrStr>::value, "");
40243da90eSArthur O'Dwyer static_assert(std::is_same<PmrStr, PmrTypedef>::value, "");
41243da90eSArthur O'Dwyer }
42243da90eSArthur O'Dwyer
43243da90eSArthur O'Dwyer template <class Char, class Traits>
test_basic_string_alias()44243da90eSArthur O'Dwyer void test_basic_string_alias() {
45243da90eSArthur O'Dwyer using StdStr = std::basic_string<Char, Traits, std::pmr::polymorphic_allocator<Char>>;
46243da90eSArthur O'Dwyer using PmrStr = std::pmr::basic_string<Char, Traits>;
47243da90eSArthur O'Dwyer static_assert(std::is_same<StdStr, PmrStr>::value, "");
48243da90eSArthur O'Dwyer }
49243da90eSArthur O'Dwyer
main(int,char **)50243da90eSArthur O'Dwyer int main(int, char**) {
51243da90eSArthur O'Dwyer {
52243da90eSArthur O'Dwyer test_string_typedef<char, std::pmr::string>();
53627465cfSNikolas Klauser #ifndef TEST_HAS_NO_WIDE_CHARACTERS
54243da90eSArthur O'Dwyer test_string_typedef<wchar_t, std::pmr::wstring>();
55627465cfSNikolas Klauser #endif
56243da90eSArthur O'Dwyer test_string_typedef<char16_t, std::pmr::u16string>();
57243da90eSArthur O'Dwyer test_string_typedef<char32_t, std::pmr::u32string>();
58243da90eSArthur O'Dwyer }
59243da90eSArthur O'Dwyer {
60243da90eSArthur O'Dwyer test_basic_string_alias<char, constexpr_char_traits<char>>();
61627465cfSNikolas Klauser #ifndef TEST_HAS_NO_WIDE_CHARACTERS
62243da90eSArthur O'Dwyer test_basic_string_alias<wchar_t, constexpr_char_traits<wchar_t>>();
63627465cfSNikolas Klauser #endif
64243da90eSArthur O'Dwyer test_basic_string_alias<char16_t, constexpr_char_traits<char16_t>>();
65243da90eSArthur O'Dwyer test_basic_string_alias<char32_t, constexpr_char_traits<char32_t>>();
66243da90eSArthur O'Dwyer }
67243da90eSArthur O'Dwyer {
68243da90eSArthur O'Dwyer // Check that std::basic_string has been included and is complete.
69243da90eSArthur O'Dwyer std::pmr::string s;
70243da90eSArthur O'Dwyer assert(s.get_allocator().resource() == std::pmr::get_default_resource());
71243da90eSArthur O'Dwyer }
72243da90eSArthur O'Dwyer
73243da90eSArthur O'Dwyer return 0;
74243da90eSArthur O'Dwyer }
75