blob: c05346a633e9a3473e1d5942e856f9c38aceef8e [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
Asiri Rathnayakef520c142015-11-10 11:41:22 +000010// XFAIL: libcpp-no-exceptions
Howard Hinnant3e519522010-05-11 19:42:16 +000011// <string>
12
13// size_type capacity() const;
14
15#include <string>
16#include <cassert>
17
Marshall Clowc3deeb52013-12-03 00:18:10 +000018#include "test_allocator.h"
Marshall Clowe34f6f62013-11-26 20:58:02 +000019#include "min_allocator.h"
Howard Hinnant3e519522010-05-11 19:42:16 +000020
21template <class S>
22void
23test(S s)
24{
25 S::allocator_type::throw_after = 0;
26 try
27 {
28 while (s.size() < s.capacity())
29 s.push_back(typename S::value_type());
30 assert(s.size() == s.capacity());
31 }
32 catch (...)
33 {
34 assert(false);
35 }
36 S::allocator_type::throw_after = INT_MAX;
37}
38
39int main()
40{
Howard Hinnanteec72182013-06-28 16:59:19 +000041 {
Howard Hinnant3e519522010-05-11 19:42:16 +000042 typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
43 S s;
44 test(s);
45 s.assign(10, 'a');
46 s.erase(5);
47 test(s);
48 s.assign(100, 'a');
49 s.erase(50);
50 test(s);
Howard Hinnanteec72182013-06-28 16:59:19 +000051 }
52#if __cplusplus >= 201103L
53 {
54 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
55 S s;
56 assert(s.capacity() > 0);
57 }
58#endif
Howard Hinnant3e519522010-05-11 19:42:16 +000059}