15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // <string>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // template<class charT, class traits, class Allocator>
125a83710eSEric Fiselier //   basic_string<charT,traits,Allocator>
13*425620ccSNikolas Klauser //   operator+(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs); // constexpr since C++20
145a83710eSEric Fiselier 
155a83710eSEric Fiselier // template<class charT, class traits, class Allocator>
165a83710eSEric Fiselier //   basic_string<charT,traits,Allocator>&&
17*425620ccSNikolas Klauser //   operator+(basic_string<charT,traits,Allocator>&& lhs, const charT* rhs); // constexpr since C++20
185a83710eSEric Fiselier 
195a83710eSEric Fiselier #include <string>
20e21582e7SMarshall Clow #include <utility>
215a83710eSEric Fiselier #include <cassert>
225a83710eSEric Fiselier 
23414d17c6SEric Fiselier #include "test_macros.h"
245a83710eSEric Fiselier #include "min_allocator.h"
255a83710eSEric Fiselier 
265a83710eSEric Fiselier template <class S>
test0(const S & lhs,const typename S::value_type * rhs,const S & x)2730046a31SNikolas Klauser TEST_CONSTEXPR_CXX20 void test0(const S& lhs, const typename S::value_type* rhs, const S& x) {
285a83710eSEric Fiselier   assert(lhs + rhs == x);
295a83710eSEric Fiselier }
305a83710eSEric Fiselier 
31414d17c6SEric Fiselier #if TEST_STD_VER >= 11
325a83710eSEric Fiselier template <class S>
test1(S && lhs,const typename S::value_type * rhs,const S & x)3330046a31SNikolas Klauser TEST_CONSTEXPR_CXX20 void test1(S&& lhs, const typename S::value_type* rhs, const S& x) {
3478533711SArthur O'Dwyer   assert(std::move(lhs) + rhs == x);
355a83710eSEric Fiselier }
36414d17c6SEric Fiselier #endif
375a83710eSEric Fiselier 
test()38*425620ccSNikolas Klauser TEST_CONSTEXPR_CXX20 bool test() {
395a83710eSEric Fiselier   {
405a83710eSEric Fiselier     typedef std::string S;
415a83710eSEric Fiselier     test0(S(""), "", S(""));
425a83710eSEric Fiselier     test0(S(""), "12345", S("12345"));
435a83710eSEric Fiselier     test0(S(""), "1234567890", S("1234567890"));
445a83710eSEric Fiselier     test0(S(""), "12345678901234567890", S("12345678901234567890"));
455a83710eSEric Fiselier     test0(S("abcde"), "", S("abcde"));
465a83710eSEric Fiselier     test0(S("abcde"), "12345", S("abcde12345"));
475a83710eSEric Fiselier     test0(S("abcde"), "1234567890", S("abcde1234567890"));
485a83710eSEric Fiselier     test0(S("abcde"), "12345678901234567890", S("abcde12345678901234567890"));
495a83710eSEric Fiselier     test0(S("abcdefghij"), "", S("abcdefghij"));
505a83710eSEric Fiselier     test0(S("abcdefghij"), "12345", S("abcdefghij12345"));
515a83710eSEric Fiselier     test0(S("abcdefghij"), "1234567890", S("abcdefghij1234567890"));
52414d17c6SEric Fiselier     test0(S("abcdefghij"), "12345678901234567890",
53414d17c6SEric Fiselier           S("abcdefghij12345678901234567890"));
545a83710eSEric Fiselier     test0(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst"));
555a83710eSEric Fiselier     test0(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345"));
56414d17c6SEric Fiselier     test0(S("abcdefghijklmnopqrst"), "1234567890",
57414d17c6SEric Fiselier           S("abcdefghijklmnopqrst1234567890"));
58414d17c6SEric Fiselier     test0(S("abcdefghijklmnopqrst"), "12345678901234567890",
59414d17c6SEric Fiselier           S("abcdefghijklmnopqrst12345678901234567890"));
60414d17c6SEric Fiselier   }
61414d17c6SEric Fiselier #if TEST_STD_VER >= 11
62414d17c6SEric Fiselier   {
63414d17c6SEric Fiselier     typedef std::string S;
645a83710eSEric Fiselier     test1(S(""), "", S(""));
655a83710eSEric Fiselier     test1(S(""), "12345", S("12345"));
665a83710eSEric Fiselier     test1(S(""), "1234567890", S("1234567890"));
675a83710eSEric Fiselier     test1(S(""), "12345678901234567890", S("12345678901234567890"));
685a83710eSEric Fiselier     test1(S("abcde"), "", S("abcde"));
695a83710eSEric Fiselier     test1(S("abcde"), "12345", S("abcde12345"));
705a83710eSEric Fiselier     test1(S("abcde"), "1234567890", S("abcde1234567890"));
715a83710eSEric Fiselier     test1(S("abcde"), "12345678901234567890", S("abcde12345678901234567890"));
725a83710eSEric Fiselier     test1(S("abcdefghij"), "", S("abcdefghij"));
735a83710eSEric Fiselier     test1(S("abcdefghij"), "12345", S("abcdefghij12345"));
745a83710eSEric Fiselier     test1(S("abcdefghij"), "1234567890", S("abcdefghij1234567890"));
75414d17c6SEric Fiselier     test1(S("abcdefghij"), "12345678901234567890",
76414d17c6SEric Fiselier           S("abcdefghij12345678901234567890"));
775a83710eSEric Fiselier     test1(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst"));
785a83710eSEric Fiselier     test1(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345"));
79414d17c6SEric Fiselier     test1(S("abcdefghijklmnopqrst"), "1234567890",
80414d17c6SEric Fiselier           S("abcdefghijklmnopqrst1234567890"));
81414d17c6SEric Fiselier     test1(S("abcdefghijklmnopqrst"), "12345678901234567890",
82414d17c6SEric Fiselier           S("abcdefghijklmnopqrst12345678901234567890"));
835a83710eSEric Fiselier   }
845a83710eSEric Fiselier   {
85414d17c6SEric Fiselier     typedef std::basic_string<char, std::char_traits<char>,
86414d17c6SEric Fiselier                               min_allocator<char> >
87414d17c6SEric Fiselier         S;
885a83710eSEric Fiselier     test0(S(""), "", S(""));
895a83710eSEric Fiselier     test0(S(""), "12345", S("12345"));
905a83710eSEric Fiselier     test0(S(""), "1234567890", S("1234567890"));
915a83710eSEric Fiselier     test0(S(""), "12345678901234567890", S("12345678901234567890"));
925a83710eSEric Fiselier     test0(S("abcde"), "", S("abcde"));
935a83710eSEric Fiselier     test0(S("abcde"), "12345", S("abcde12345"));
945a83710eSEric Fiselier     test0(S("abcde"), "1234567890", S("abcde1234567890"));
955a83710eSEric Fiselier     test0(S("abcde"), "12345678901234567890", S("abcde12345678901234567890"));
965a83710eSEric Fiselier     test0(S("abcdefghij"), "", S("abcdefghij"));
975a83710eSEric Fiselier     test0(S("abcdefghij"), "12345", S("abcdefghij12345"));
985a83710eSEric Fiselier     test0(S("abcdefghij"), "1234567890", S("abcdefghij1234567890"));
99414d17c6SEric Fiselier     test0(S("abcdefghij"), "12345678901234567890",
100414d17c6SEric Fiselier           S("abcdefghij12345678901234567890"));
1015a83710eSEric Fiselier     test0(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst"));
1025a83710eSEric Fiselier     test0(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345"));
103414d17c6SEric Fiselier     test0(S("abcdefghijklmnopqrst"), "1234567890",
104414d17c6SEric Fiselier           S("abcdefghijklmnopqrst1234567890"));
105414d17c6SEric Fiselier     test0(S("abcdefghijklmnopqrst"), "12345678901234567890",
106414d17c6SEric Fiselier           S("abcdefghijklmnopqrst12345678901234567890"));
1075a83710eSEric Fiselier 
1085a83710eSEric Fiselier     test1(S(""), "", S(""));
1095a83710eSEric Fiselier     test1(S(""), "12345", S("12345"));
1105a83710eSEric Fiselier     test1(S(""), "1234567890", S("1234567890"));
1115a83710eSEric Fiselier     test1(S(""), "12345678901234567890", S("12345678901234567890"));
1125a83710eSEric Fiselier     test1(S("abcde"), "", S("abcde"));
1135a83710eSEric Fiselier     test1(S("abcde"), "12345", S("abcde12345"));
1145a83710eSEric Fiselier     test1(S("abcde"), "1234567890", S("abcde1234567890"));
1155a83710eSEric Fiselier     test1(S("abcde"), "12345678901234567890", S("abcde12345678901234567890"));
1165a83710eSEric Fiselier     test1(S("abcdefghij"), "", S("abcdefghij"));
1175a83710eSEric Fiselier     test1(S("abcdefghij"), "12345", S("abcdefghij12345"));
1185a83710eSEric Fiselier     test1(S("abcdefghij"), "1234567890", S("abcdefghij1234567890"));
119414d17c6SEric Fiselier     test1(S("abcdefghij"), "12345678901234567890",
120414d17c6SEric Fiselier           S("abcdefghij12345678901234567890"));
1215a83710eSEric Fiselier     test1(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst"));
1225a83710eSEric Fiselier     test1(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345"));
123414d17c6SEric Fiselier     test1(S("abcdefghijklmnopqrst"), "1234567890",
124414d17c6SEric Fiselier           S("abcdefghijklmnopqrst1234567890"));
125414d17c6SEric Fiselier     test1(S("abcdefghijklmnopqrst"), "12345678901234567890",
126414d17c6SEric Fiselier           S("abcdefghijklmnopqrst12345678901234567890"));
1275a83710eSEric Fiselier   }
1285a83710eSEric Fiselier #endif
1292df59c50SJF Bastien 
13030046a31SNikolas Klauser   return true;
13130046a31SNikolas Klauser }
13230046a31SNikolas Klauser 
main(int,char **)13330046a31SNikolas Klauser int main(int, char**) {
13430046a31SNikolas Klauser   test();
13530046a31SNikolas Klauser #if TEST_STD_VER > 17
136*425620ccSNikolas Klauser   static_assert(test());
13730046a31SNikolas Klauser #endif
13830046a31SNikolas Klauser 
1392df59c50SJF Bastien   return 0;
1405a83710eSEric Fiselier }
141