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 //===----------------------------------------------------------------------===//
11 // void swap(basic_string& s); // constexpr since C++20
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "asan_testing.h"
21 #include "operator_hijacker.h"
24 TEST_CONSTEXPR_CXX20
void test(S s1
, S s2
) {
28 LIBCPP_ASSERT(s1
.__invariants());
29 LIBCPP_ASSERT(s2
.__invariants());
32 LIBCPP_ASSERT(is_string_asan_correct(s1
));
33 LIBCPP_ASSERT(is_string_asan_correct(s2
));
37 TEST_CONSTEXPR_CXX20
void test_string() {
39 test(S(""), S("12345"));
40 test(S(""), S("1234567890"));
41 test(S(""), S("12345678901234567890"));
42 test(S("abcde"), S(""));
43 test(S("abcde"), S("12345"));
44 test(S("abcde"), S("1234567890"));
45 test(S("abcde"), S("12345678901234567890"));
46 test(S("abcdefghij"), S(""));
47 test(S("abcdefghij"), S("12345"));
48 test(S("abcdefghij"), S("1234567890"));
49 test(S("abcdefghij"), S("12345678901234567890"));
50 test(S("abcdefghijklmnopqrst"), S(""));
51 test(S("abcdefghijklmnopqrst"), S("12345"));
52 test(S("abcdefghijklmnopqrst"), S("1234567890"));
53 test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
54 test(S("abcdefghijklmnopqrstabcdefghijklmnopqrst"), S(""));
55 test(S("abcdefghijklmnopqrstabcdefghijklmnopqrst"), S("12345"));
56 test(S("abcdefghijklmnopqrstabcdefghijklmnopqrst"), S("1234567890"));
57 test(S("abcdefghijklmnopqrstabcdefghijklmnopqrst"), S("12345678901234567890"));
58 test(S("abcdefghijklmnopqrstabcdefghijklmnopqrst"), S("12345678901234567890abcdefghijklmnopqrst"));
61 TEST_CONSTEXPR_CXX20
bool test() {
62 test_string
<std::string
>();
63 #if TEST_STD_VER >= 11
64 test_string
<std::basic_string
<char, std::char_traits
<char>, min_allocator
<char>>>();
65 test_string
<std::basic_string
<char, std::char_traits
<char>, safe_allocator
<char>>>();
66 test_string
<std::basic_string
<char, std::char_traits
<char>, operator_hijacker_allocator
<char>>>();
72 int main(int, char**) {
75 static_assert(test());