1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++03
10
11 // Aligned allocation is required by std::experimental::pmr, but it was not provided
12 // before macosx10.13 and as a result we get linker errors when deploying to older than
13 // macosx10.13.
14 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}
15
16 // <experimental/string>
17
18 // namespace std { namespace experimental { namespace pmr {
19 // template <class Char, class Traits = ...>
20 // using basic_string =
21 // ::std::basic_string<Char, Traits, polymorphic_allocator<Char>>
22 //
23 // typedef ... string
24 // typedef ... u16string
25 // typedef ... u32string
26 // typedef ... wstring
27 //
28 // }}} // namespace std::experimental::pmr
29
30 #include <experimental/string>
31 #include <experimental/memory_resource>
32 #include <type_traits>
33 #include <cassert>
34
35 #include "constexpr_char_traits.h"
36
37 #include "test_macros.h"
38
39 namespace pmr = std::experimental::pmr;
40
41 template <class Char, class PmrTypedef>
test_string_typedef()42 void test_string_typedef() {
43 using StdStr = std::basic_string<Char, std::char_traits<Char>,
44 pmr::polymorphic_allocator<Char>>;
45 using PmrStr = pmr::basic_string<Char>;
46 static_assert(std::is_same<StdStr, PmrStr>::value, "");
47 static_assert(std::is_same<PmrStr, PmrTypedef>::value, "");
48 }
49
50 template <class Char, class Traits>
test_basic_string_alias()51 void test_basic_string_alias() {
52 using StdStr = std::basic_string<Char, Traits,
53 pmr::polymorphic_allocator<Char>>;
54 using PmrStr = pmr::basic_string<Char, Traits>;
55 static_assert(std::is_same<StdStr, PmrStr>::value, "");
56 }
57
main(int,char **)58 int main(int, char**)
59 {
60 {
61 test_string_typedef<char, pmr::string>();
62 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
63 test_string_typedef<wchar_t, pmr::wstring>();
64 #endif
65 test_string_typedef<char16_t, pmr::u16string>();
66 test_string_typedef<char32_t, pmr::u32string>();
67 }
68 {
69 test_basic_string_alias<char, constexpr_char_traits<char>>();
70 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
71 test_basic_string_alias<wchar_t, constexpr_char_traits<wchar_t>>();
72 #endif
73 test_basic_string_alias<char16_t, constexpr_char_traits<char16_t>>();
74 test_basic_string_alias<char32_t, constexpr_char_traits<char32_t>>();
75 }
76 {
77 // Check that std::basic_string has been included and is complete.
78 pmr::string s;
79 assert(s.get_allocator().resource() == pmr::get_default_resource());
80 }
81
82 return 0;
83 }
84