over_max_size.pass.cpp 1.4 KB

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