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 // <string>
10
11 // template<class charT, class traits, class Allocator>
12 // basic_string<charT,traits,Allocator>
13 // operator+(const basic_string<charT,traits,Allocator>& lhs,
14 // const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20
15
16 // template<class charT, class traits, class Allocator>
17 // basic_string<charT,traits,Allocator>&&
18 // operator+(const basic_string<charT,traits,Allocator>&& lhs,
19 // const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20
20
21 // template<class charT, class traits, class Allocator>
22 // basic_string<charT,traits,Allocator>&&
23 // operator+(const basic_string<charT,traits,Allocator>& lhs,
24 // const basic_string<charT,traits,Allocator>&& rhs); // constexpr since C++20
25
26 // template<class charT, class traits, class Allocator>
27 // basic_string<charT,traits,Allocator>&&
28 // operator+(const basic_string<charT,traits,Allocator>&& lhs,
29 // const basic_string<charT,traits,Allocator>&& rhs); // constexpr since C++20
30
31 #include <string>
32 #include <utility>
33 #include <cassert>
34
35 #include "test_macros.h"
36 #include "min_allocator.h"
37 #include "asan_testing.h"
38
39 template <class S>
test0(const S & lhs,const S & rhs,const S & x)40 TEST_CONSTEXPR_CXX20 void test0(const S& lhs, const S& rhs, const S& x) {
41 assert(lhs + rhs == x);
42 LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs));
43 }
44
45 #if TEST_STD_VER >= 11
46 template <class S>
test1(S && lhs,const S & rhs,const S & x)47 TEST_CONSTEXPR_CXX20 void test1(S&& lhs, const S& rhs, const S& x) {
48 assert(std::move(lhs) + rhs == x);
49 }
50
51 template <class S>
test2(const S & lhs,S && rhs,const S & x)52 TEST_CONSTEXPR_CXX20 void test2(const S& lhs, S&& rhs, const S& x) {
53 assert(lhs + std::move(rhs) == x);
54 }
55
56 template <class S>
test3(S && lhs,S && rhs,const S & x)57 TEST_CONSTEXPR_CXX20 void test3(S&& lhs, S&& rhs, const S& x) {
58 assert(std::move(lhs) + std::move(rhs) == x);
59 }
60 #endif
61
62 template <class S>
test_string()63 TEST_CONSTEXPR_CXX20 void test_string() {
64 test0(S(""), S(""), S(""));
65 test0(S(""), S("12345"), S("12345"));
66 test0(S(""), S("1234567890"), S("1234567890"));
67 test0(S(""), S("12345678901234567890"), S("12345678901234567890"));
68 test0(S("abcde"), S(""), S("abcde"));
69 test0(S("abcde"), S("12345"), S("abcde12345"));
70 test0(S("abcde"), S("1234567890"), S("abcde1234567890"));
71 test0(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
72 test0(S("abcdefghij"), S(""), S("abcdefghij"));
73 test0(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
74 test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
75 test0(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
76 test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
77 test0(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
78 test0(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
79 test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
80 #if TEST_STD_VER >= 11
81 test1(S(""), S(""), S(""));
82 test1(S(""), S("12345"), S("12345"));
83 test1(S(""), S("1234567890"), S("1234567890"));
84 test1(S(""), S("12345678901234567890"), S("12345678901234567890"));
85 test1(S("abcde"), S(""), S("abcde"));
86 test1(S("abcde"), S("12345"), S("abcde12345"));
87 test1(S("abcde"), S("1234567890"), S("abcde1234567890"));
88 test1(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
89 test1(S("abcdefghij"), S(""), S("abcdefghij"));
90 test1(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
91 test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
92 test1(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
93 test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
94 test1(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
95 test1(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
96 test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
97
98 test2(S(""), S(""), S(""));
99 test2(S(""), S("12345"), S("12345"));
100 test2(S(""), S("1234567890"), S("1234567890"));
101 test2(S(""), S("12345678901234567890"), S("12345678901234567890"));
102 test2(S("abcde"), S(""), S("abcde"));
103 test2(S("abcde"), S("12345"), S("abcde12345"));
104 test2(S("abcde"), S("1234567890"), S("abcde1234567890"));
105 test2(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
106 test2(S("abcdefghij"), S(""), S("abcdefghij"));
107 test2(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
108 test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
109 test2(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
110 test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
111 test2(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
112 test2(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
113 test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
114
115 test3(S(""), S(""), S(""));
116 test3(S(""), S("12345"), S("12345"));
117 test3(S(""), S("1234567890"), S("1234567890"));
118 test3(S(""), S("12345678901234567890"), S("12345678901234567890"));
119 test3(S("abcde"), S(""), S("abcde"));
120 test3(S("abcde"), S("12345"), S("abcde12345"));
121 test3(S("abcde"), S("1234567890"), S("abcde1234567890"));
122 test3(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
123 test3(S("abcdefghij"), S(""), S("abcdefghij"));
124 test3(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
125 test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
126 test3(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
127 test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
128 test3(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
129 test3(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
130 test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
131 #endif
132 }
133
test()134 TEST_CONSTEXPR_CXX20 bool test() {
135 test_string<std::string>();
136 #if TEST_STD_VER >= 11
137 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
138 test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char> > >();
139 #endif
140
141 return true;
142 }
143
main(int,char **)144 int main(int, char**) {
145 test();
146 #if TEST_STD_VER > 17
147 static_assert(test());
148 #endif
149
150 return 0;
151 }
152