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, const charT* rhs); // constexpr since C++20
14 
15 // template<class charT, class traits, class Allocator>
16 //   basic_string<charT,traits,Allocator>&&
17 //   operator+(basic_string<charT,traits,Allocator>&& lhs, const charT* rhs); // constexpr since C++20
18 
19 #include <string>
20 #include <utility>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 #include "min_allocator.h"
25 #include "asan_testing.h"
26 
27 template <class S>
test0(const S & lhs,const typename S::value_type * rhs,const S & x)28 TEST_CONSTEXPR_CXX20 void test0(const S& lhs, const typename S::value_type* rhs, const S& x) {
29   assert(lhs + rhs == x);
30   LIBCPP_ASSERT(is_string_asan_correct(lhs + rhs));
31 }
32 
33 #if TEST_STD_VER >= 11
34 template <class S>
test1(S && lhs,const typename S::value_type * rhs,const S & x)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 template <class S>
test_string()41 TEST_CONSTEXPR_CXX20 void test_string() {
42   test0(S(""), "", S(""));
43   test0(S(""), "12345", S("12345"));
44   test0(S(""), "1234567890", S("1234567890"));
45   test0(S(""), "12345678901234567890", S("12345678901234567890"));
46   test0(S("abcde"), "", S("abcde"));
47   test0(S("abcde"), "12345", S("abcde12345"));
48   test0(S("abcde"), "1234567890", S("abcde1234567890"));
49   test0(S("abcde"), "12345678901234567890", S("abcde12345678901234567890"));
50   test0(S("abcdefghij"), "", S("abcdefghij"));
51   test0(S("abcdefghij"), "12345", S("abcdefghij12345"));
52   test0(S("abcdefghij"), "1234567890", S("abcdefghij1234567890"));
53   test0(S("abcdefghij"), "12345678901234567890", S("abcdefghij12345678901234567890"));
54   test0(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst"));
55   test0(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345"));
56   test0(S("abcdefghijklmnopqrst"), "1234567890", S("abcdefghijklmnopqrst1234567890"));
57   test0(S("abcdefghijklmnopqrst"), "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
58 #if TEST_STD_VER >= 11
59   test1(S(""), "", S(""));
60   test1(S(""), "12345", S("12345"));
61   test1(S(""), "1234567890", S("1234567890"));
62   test1(S(""), "12345678901234567890", S("12345678901234567890"));
63   test1(S("abcde"), "", S("abcde"));
64   test1(S("abcde"), "12345", S("abcde12345"));
65   test1(S("abcde"), "1234567890", S("abcde1234567890"));
66   test1(S("abcde"), "12345678901234567890", S("abcde12345678901234567890"));
67   test1(S("abcdefghij"), "", S("abcdefghij"));
68   test1(S("abcdefghij"), "12345", S("abcdefghij12345"));
69   test1(S("abcdefghij"), "1234567890", S("abcdefghij1234567890"));
70   test1(S("abcdefghij"), "12345678901234567890", S("abcdefghij12345678901234567890"));
71   test1(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst"));
72   test1(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345"));
73   test1(S("abcdefghijklmnopqrst"), "1234567890", S("abcdefghijklmnopqrst1234567890"));
74   test1(S("abcdefghijklmnopqrst"), "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
75 #endif
76 }
77 
test()78 TEST_CONSTEXPR_CXX20 bool test() {
79   test_string<std::string>();
80 #if TEST_STD_VER >= 11
81   test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
82   test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char> > >();
83 #endif
84 
85   return true;
86 }
87 
main(int,char **)88 int main(int, char**) {
89   test();
90 #if TEST_STD_VER > 17
91   static_assert(test());
92 #endif
93 
94   return 0;
95 }
96