over_max_size.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // XFAIL: libcpp-no-exceptions
  10. // <string>
  11. // size_type max_size() const;
  12. #include <string>
  13. #include <cassert>
  14. #include "min_allocator.h"
  15. template <class S>
  16. void
  17. test(const S& s)
  18. {
  19. assert(s.max_size() >= s.size());
  20. S s2(s);
  21. const size_t sz = s2.max_size() + 1;
  22. try { s2.resize(sz, 'x'); }
  23. catch ( const std::length_error & ) { return ; }
  24. assert ( false );
  25. }
  26. int main()
  27. {
  28. {
  29. typedef std::string S;
  30. test(S());
  31. test(S("123"));
  32. test(S("12345678901234567890123456789012345678901234567890"));
  33. }
  34. #if __cplusplus >= 201103L
  35. {
  36. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  37. test(S());
  38. test(S("123"));
  39. test(S("12345678901234567890123456789012345678901234567890"));
  40. }
  41. #endif
  42. }