]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp
Vendor import of libc++ trunk r256633:
[FreeBSD/FreeBSD.git] / test / std / strings / basic.string / string.capacity / over_max_size.pass.cpp
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 // XFAIL: libcpp-no-exceptions
11 // <string>
12
13 // size_type max_size() const;
14
15 #include <string>
16 #include <cassert>
17
18 #include "min_allocator.h"
19
20 template <class S>
21 void
22 test(const S& s)
23 {
24     assert(s.max_size() >= s.size());
25     S s2(s);
26     const size_t sz = s2.max_size() + 1;
27     try { s2.resize(sz, 'x'); }
28     catch ( const std::length_error & ) { return ; }
29     assert ( false );
30 }
31
32 int main()
33 {
34     {
35     typedef std::string S;
36     test(S());
37     test(S("123"));
38     test(S("12345678901234567890123456789012345678901234567890"));
39     }
40 #if __cplusplus >= 201103L
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 }