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 // basic_string<charT,traits,Allocator>& operator+=(charT c); // constexpr since C++20
12
13 #include <string>
14 #include <cassert>
15
16 #include "test_macros.h"
17 #include "min_allocator.h"
18 #include "asan_testing.h"
19
20 template <class S>
test(S s,typename S::value_type str,S expected)21 TEST_CONSTEXPR_CXX20 void test(S s, typename S::value_type str, S expected) {
22 s += str;
23 LIBCPP_ASSERT(s.__invariants());
24 assert(s == expected);
25 LIBCPP_ASSERT(is_string_asan_correct(s));
26 }
27
28 template <class S>
test_string()29 TEST_CONSTEXPR_CXX20 void test_string() {
30 test(S(), 'a', S("a"));
31 test(S("12345"), 'a', S("12345a"));
32 test(S("1234567890"), 'a', S("1234567890a"));
33 test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
34 test(S("1234567890123456789012345678901234567890"), 'a', S("1234567890123456789012345678901234567890a"));
35 }
36
test()37 TEST_CONSTEXPR_CXX20 bool test() {
38 test_string<std::string>();
39 #if TEST_STD_VER >= 11
40 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
41 test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char> > >();
42 #endif
43
44 return true;
45 }
46
main(int,char **)47 int main(int, char**) {
48 test();
49 #if TEST_STD_VER > 17
50 static_assert(test());
51 #endif
52
53 return 0;
54 }
55