libcxx

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

over_max_size.pass.cpp (1363B)


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