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