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, 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, 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, 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, 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(""), '1', S("1"));
44     test0(S("abcde"), '1', S("abcde1"));
45     test0(S("abcdefghij"), '1', S("abcdefghij1"));
46     test0(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
47   }
48 #if TEST_STD_VER >= 11
49   {
50     typedef std::string S;
51     test1(S(""), '1', S("1"));
52     test1(S("abcde"), '1', S("abcde1"));
53     test1(S("abcdefghij"), '1', S("abcdefghij1"));
54     test1(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
55   }
56   {
57     typedef std::basic_string<char, std::char_traits<char>,
58                               min_allocator<char> >
59         S;
60     test0(S(""), '1', S("1"));
61     test0(S("abcde"), '1', S("abcde1"));
62     test0(S("abcdefghij"), '1', S("abcdefghij1"));
63     test0(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
64 
65     test1(S(""), '1', S("1"));
66     test1(S("abcde"), '1', S("abcde1"));
67     test1(S("abcdefghij"), '1', S("abcdefghij1"));
68     test1(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
69   }
70 #endif
71 
72   return true;
73 }
74 
75 int main(int, char**) {
76   test();
77 #if TEST_STD_VER > 17
78   static_assert(test());
79 #endif
80 
81   return 0;
82 }
83