Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Asiri Rathnayake | f520c14 | 2015-11-10 11:41:22 +0000 | [diff] [blame] | 10 | // XFAIL: libcpp-no-exceptions |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 11 | // <string> |
| 12 | |
| 13 | // size_type capacity() const; |
| 14 | |
| 15 | #include <string> |
| 16 | #include <cassert> |
| 17 | |
Marshall Clow | c3deeb5 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 18 | #include "test_allocator.h" |
Marshall Clow | e34f6f6 | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 19 | #include "min_allocator.h" |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | |
| 21 | template <class S> |
| 22 | void |
| 23 | test(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 | |
| 39 | int main() |
| 40 | { |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 41 | { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | 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 Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 51 | } |
| 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 Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | } |