1 // Copyright (C) 2007 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without Pred the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // 23.2.5 class vector<bool> [lib.vector.bool]
21 // { dg-do run { xfail *-*-darwin8.[0-4].* } }
25 #include <testsuite_hooks.h>
28 check_cap_ge_size(const std::vector<bool>& x)
30 if (x.capacity() < x.size())
31 throw std::logic_error("");
35 check_cap_eq_maxsize(const std::vector<bool>& x)
37 if (x.capacity() != x.max_size())
38 throw std::logic_error("");
44 bool test __attribute__((unused)) = true;
50 x.reserve(x.max_size());
51 check_cap_eq_maxsize(x);
53 catch(std::bad_alloc&)
55 catch(std::exception&)
58 // When doubling is too big, but smaller is sufficient, the resize
59 // should do smaller and be happy. It certainly shouldn't throw
60 // other exceptions or crash.
64 x.resize(x.max_size() / 2 + 1, false);
65 for(int i = 0; i < std::_S_word_bit; ++i)
69 catch(std::bad_alloc&)
71 catch(std::exception&)
77 x.resize(x.max_size() / 2 + 1, false);
78 x.insert(x.end(), std::_S_word_bit, false);
81 catch(std::bad_alloc&)
83 catch(std::exception&)
89 x.resize(x.max_size() / 2 + 1, false);
90 std::vector<bool> y(std::_S_word_bit, false);
91 x.insert(x.end(), y.begin(), y.end());
94 catch(std::bad_alloc&)
96 catch(std::exception&)
99 // These tests are currently only relevant to bool: don't get burned
100 // by the attempt to round up when near the max size.
104 x.resize(x.max_size() - std::_S_word_bit, false);
105 for(int i = 0; i < std::_S_word_bit; ++i)
107 check_cap_ge_size(x);
109 catch(std::bad_alloc&)
111 catch(std::exception&)
117 x.resize(x.max_size() - std::_S_word_bit, false);
118 x.insert(x.end(), std::_S_word_bit, false);
119 check_cap_ge_size(x);
121 catch(std::bad_alloc&)
123 catch(std::exception&)
129 x.resize(x.max_size() - std::_S_word_bit, false);
130 std::vector<bool> y(std::_S_word_bit, false);
131 x.insert(x.end(), y.begin(), y.end());
132 check_cap_ge_size(x);
134 catch(std::bad_alloc&)
136 catch(std::exception&)
139 // Attempts to put in more than max_size() items should result in a
144 x.resize(x.max_size() - std::_S_word_bit, false);
145 for(int i = 0; i < std::_S_word_bit + 1; ++i)
149 catch(std::bad_alloc)
151 catch(std::length_error)
153 catch(std::exception)
159 x.resize(x.max_size() - std::_S_word_bit, false);
160 x.insert(x.end(), std::_S_word_bit + 1, false);
163 catch(std::bad_alloc)
165 catch(std::length_error)
167 catch(std::exception)
173 x.resize(x.max_size() - std::_S_word_bit, false);
174 std::vector<bool> y(std::_S_word_bit + 1, false);
175 x.insert(x.end(), y.begin(), y.end());
178 catch(std::bad_alloc)
180 catch(std::length_error)
182 catch(std::exception)