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+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20
14
15 // template<class charT, class traits, class Allocator>
16 // basic_string<charT,traits,Allocator>&&
17 // operator+(charT lhs, basic_string<charT,traits,Allocator>&& 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(typename S::value_type lhs,const S & rhs,const S & x)28 TEST_CONSTEXPR_CXX20 void test0(typename S::value_type lhs, const S& 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(typename S::value_type lhs,S && rhs,const S & x)35 TEST_CONSTEXPR_CXX20 void test1(typename S::value_type lhs, S&& rhs, const S& x) {
36 assert(lhs + std::move(rhs) == x);
37 }
38 #endif
39
40 template <class S>
test_string()41 TEST_CONSTEXPR_CXX20 void test_string() {
42 test0('a', S(""), S("a"));
43 test0('a', S("12345"), S("a12345"));
44 test0('a', S("1234567890"), S("a1234567890"));
45 test0('a', S("12345678901234567890"), S("a12345678901234567890"));
46 #if TEST_STD_VER >= 11
47 test1('a', S(""), S("a"));
48 test1('a', S("12345"), S("a12345"));
49 test1('a', S("1234567890"), S("a1234567890"));
50 test1('a', S("12345678901234567890"), S("a12345678901234567890"));
51 #endif
52 }
53
test()54 TEST_CONSTEXPR_CXX20 bool test() {
55 test_string<std::string>();
56 #if TEST_STD_VER >= 11
57 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
58 test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char> > >();
59 #endif
60
61 return true;
62 }
63
main(int,char **)64 int main(int, char**) {
65 test();
66 #if TEST_STD_VER > 17
67 static_assert(test());
68 #endif
69
70 return 0;
71 }
72