1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
10 // TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed
11 // UNSUPPORTED: availability-pmr-missing
15 // namespace std::pmr {
16 // template <class Char, class Traits = ...>
17 // using basic_string =
18 // ::std::basic_string<Char, Traits, polymorphic_allocator<Char>>
21 // typedef ... u16string
22 // typedef ... u32string
23 // typedef ... wstring
25 // } // namespace std::pmr
29 #include <memory_resource>
30 #include <type_traits>
32 #include "constexpr_char_traits.h"
33 #include "test_macros.h"
35 template <class Char
, class PmrTypedef
>
36 void test_string_typedef() {
37 using StdStr
= std::basic_string
<Char
, std::char_traits
<Char
>, std::pmr::polymorphic_allocator
<Char
>>;
38 using PmrStr
= std::pmr::basic_string
<Char
>;
39 static_assert(std::is_same
<StdStr
, PmrStr
>::value
, "");
40 static_assert(std::is_same
<PmrStr
, PmrTypedef
>::value
, "");
43 template <class Char
, class Traits
>
44 void test_basic_string_alias() {
45 using StdStr
= std::basic_string
<Char
, Traits
, std::pmr::polymorphic_allocator
<Char
>>;
46 using PmrStr
= std::pmr::basic_string
<Char
, Traits
>;
47 static_assert(std::is_same
<StdStr
, PmrStr
>::value
, "");
50 int main(int, char**) {
52 test_string_typedef
<char, std::pmr::string
>();
53 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
54 test_string_typedef
<wchar_t, std::pmr::wstring
>();
56 test_string_typedef
<char16_t
, std::pmr::u16string
>();
57 test_string_typedef
<char32_t
, std::pmr::u32string
>();
60 test_basic_string_alias
<char, constexpr_char_traits
<char>>();
61 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
62 test_basic_string_alias
<wchar_t, constexpr_char_traits
<wchar_t>>();
64 test_basic_string_alias
<char16_t
, constexpr_char_traits
<char16_t
>>();
65 test_basic_string_alias
<char32_t
, constexpr_char_traits
<char32_t
>>();
68 // Check that std::basic_string has been included and is complete.
70 assert(s
.get_allocator().resource() == std::pmr::get_default_resource());