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 // void push_back(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 19 struct veryLarge 20 { 21 long long a; 22 char b; 23 }; 24 25 template <class S> 26 TEST_CONSTEXPR_CXX20 void 27 test(S s, typename S::value_type c, S expected) 28 { 29 s.push_back(c); 30 LIBCPP_ASSERT(s.__invariants()); 31 assert(s == expected); 32 } 33 34 TEST_CONSTEXPR_CXX20 bool test() { 35 { 36 typedef std::string S; 37 test(S(), 'a', S(1, 'a')); 38 test(S("12345"), 'a', S("12345a")); 39 test(S("12345678901234567890"), 'a', S("12345678901234567890a")); 40 } 41 #if TEST_STD_VER >= 11 42 { 43 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 44 test(S(), 'a', S(1, 'a')); 45 test(S("12345"), 'a', S("12345a")); 46 test(S("12345678901234567890"), 'a', S("12345678901234567890a")); 47 } 48 #endif 49 50 { 51 // https://llvm.org/PR31454 52 std::basic_string<veryLarge> s; 53 veryLarge vl = {}; 54 s.push_back(vl); 55 s.push_back(vl); 56 s.push_back(vl); 57 } 58 59 return true; 60 } 61 62 int main(int, char**) 63 { 64 test(); 65 #if TEST_STD_VER > 17 66 static_assert(test()); 67 #endif 68 69 return 0; 70 } 71