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