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 
11*425620ccSNikolas Klauser // void push_back(charT c) // constexpr since C++20
125a83710eSEric Fiselier 
135a83710eSEric Fiselier #include <string>
145a83710eSEric Fiselier #include <cassert>
155a83710eSEric Fiselier 
161f4231f8SEric Fiselier #include "test_macros.h"
175a83710eSEric Fiselier #include "min_allocator.h"
185a83710eSEric Fiselier 
19800259c9SMarshall Clow struct veryLarge
20800259c9SMarshall Clow {
21800259c9SMarshall Clow   long long a;
22800259c9SMarshall Clow   char b;
23800259c9SMarshall Clow };
24800259c9SMarshall Clow 
255a83710eSEric Fiselier template <class S>
26dcffa7d3SNikolas Klauser TEST_CONSTEXPR_CXX20 void
test(S s,typename S::value_type c,S expected)275a83710eSEric Fiselier test(S s, typename S::value_type c, S expected)
285a83710eSEric Fiselier {
295a83710eSEric Fiselier     s.push_back(c);
301f4231f8SEric Fiselier     LIBCPP_ASSERT(s.__invariants());
315a83710eSEric Fiselier     assert(s == expected);
325a83710eSEric Fiselier }
335a83710eSEric Fiselier 
test()34*425620ccSNikolas Klauser TEST_CONSTEXPR_CXX20 bool test() {
355a83710eSEric Fiselier   {
365a83710eSEric Fiselier     typedef std::string S;
375a83710eSEric Fiselier     test(S(), 'a', S(1, 'a'));
385a83710eSEric Fiselier     test(S("12345"), 'a', S("12345a"));
395a83710eSEric Fiselier     test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
405a83710eSEric Fiselier   }
4176b4afc0SMarshall Clow #if TEST_STD_VER >= 11
425a83710eSEric Fiselier   {
435a83710eSEric Fiselier     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
445a83710eSEric Fiselier     test(S(), 'a', S(1, 'a'));
455a83710eSEric Fiselier     test(S("12345"), 'a', S("12345a"));
465a83710eSEric Fiselier     test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
475a83710eSEric Fiselier   }
485a83710eSEric Fiselier #endif
49fc940277SMarshall Clow 
50800259c9SMarshall Clow   {
513c62198cSLouis Dionne // https://llvm.org/PR31454
52800259c9SMarshall Clow     std::basic_string<veryLarge> s;
53c1fcd97eSStephan T. Lavavej     veryLarge vl = {};
54800259c9SMarshall Clow     s.push_back(vl);
55800259c9SMarshall Clow     s.push_back(vl);
56800259c9SMarshall Clow     s.push_back(vl);
57800259c9SMarshall Clow   }
582df59c50SJF Bastien 
59dcffa7d3SNikolas Klauser   return true;
60dcffa7d3SNikolas Klauser }
61dcffa7d3SNikolas Klauser 
main(int,char **)62dcffa7d3SNikolas Klauser int main(int, char**)
63dcffa7d3SNikolas Klauser {
64dcffa7d3SNikolas Klauser   test();
65dcffa7d3SNikolas Klauser #if TEST_STD_VER > 17
66*425620ccSNikolas Klauser   static_assert(test());
67dcffa7d3SNikolas Klauser #endif
68dcffa7d3SNikolas Klauser 
692df59c50SJF Bastien   return 0;
705a83710eSEric Fiselier }
71