push_back.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // <string>
  10. // void push_back(charT c)
  11. #include <string>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "min_allocator.h"
  15. struct veryLarge
  16. {
  17. long long a;
  18. char b;
  19. };
  20. template <class S>
  21. void
  22. test(S s, typename S::value_type c, S expected)
  23. {
  24. s.push_back(c);
  25. LIBCPP_ASSERT(s.__invariants());
  26. assert(s == expected);
  27. }
  28. int main()
  29. {
  30. {
  31. typedef std::string S;
  32. test(S(), 'a', S(1, 'a'));
  33. test(S("12345"), 'a', S("12345a"));
  34. test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
  35. }
  36. #if TEST_STD_VER >= 11
  37. {
  38. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  39. test(S(), 'a', S(1, 'a'));
  40. test(S("12345"), 'a', S("12345a"));
  41. test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
  42. }
  43. #endif
  44. {
  45. // https://bugs.llvm.org/show_bug.cgi?id=31454
  46. std::basic_string<veryLarge> s;
  47. veryLarge vl;
  48. s.push_back(vl);
  49. s.push_back(vl);
  50. s.push_back(vl);
  51. }
  52. }