libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

push_back.pass.cpp (1342B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <string>
     11 
     12 // void push_back(charT c)
     13 
     14 #include <string>
     15 #include <cassert>
     16 
     17 #include "test_macros.h"
     18 #include "min_allocator.h"
     19 
     20 struct veryLarge
     21 {
     22   long long a;
     23   char b;
     24 };
     25 
     26 template <class S>
     27 void
     28 test(S s, typename S::value_type c, S expected)
     29 {
     30     s.push_back(c);
     31     LIBCPP_ASSERT(s.__invariants());
     32     assert(s == expected);
     33 }
     34 
     35 int main()
     36 {
     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://bugs.llvm.org/show_bug.cgi?id=31454
     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 }