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>
27 #ifndef _GLIBCXX_DEBUG
28 using std::_S_word_bit;
30 using std::_GLIBCXX_STD_D::_S_word_bit;
34 check_cap_ge_size(const std::vector<bool>& x)
36 if (x.capacity() < x.size())
37 throw std::logic_error("");
41 check_cap_eq_maxsize(const std::vector<bool>& x)
43 if (x.capacity() != x.max_size())
44 throw std::logic_error("");
50 bool test __attribute__((unused)) = true;
56 x.reserve(x.max_size());
57 check_cap_eq_maxsize(x);
59 catch(std::bad_alloc&)
61 catch(std::exception&)
64 // When doubling is too big, but smaller is sufficient, the resize
65 // should do smaller and be happy. It certainly shouldn't throw
66 // other exceptions or crash.
70 x.resize(x.max_size() / 2 + 1, false);
71 for(int i = 0; i < _S_word_bit; ++i)
75 catch(std::bad_alloc&)
77 catch(std::exception&)
83 x.resize(x.max_size() / 2 + 1, false);
84 x.insert(x.end(), _S_word_bit, false);
87 catch(std::bad_alloc&)
89 catch(std::exception&)
95 x.resize(x.max_size() / 2 + 1, false);
96 std::vector<bool> y(_S_word_bit, false);
97 x.insert(x.end(), y.begin(), y.end());
100 catch(std::bad_alloc&)
102 catch(std::exception&)
105 // These tests are currently only relevant to bool: don't get burned
106 // by the attempt to round up when near the max size.
110 x.resize(x.max_size() - _S_word_bit, false);
111 for(int i = 0; i < _S_word_bit; ++i)
113 check_cap_ge_size(x);
115 catch(std::bad_alloc&)
117 catch(std::exception&)
123 x.resize(x.max_size() - _S_word_bit, false);
124 x.insert(x.end(), _S_word_bit, false);
125 check_cap_ge_size(x);
127 catch(std::bad_alloc&)
129 catch(std::exception&)
135 x.resize(x.max_size() - _S_word_bit, false);
136 std::vector<bool> y(_S_word_bit, false);
137 x.insert(x.end(), y.begin(), y.end());
138 check_cap_ge_size(x);
140 catch(std::bad_alloc&)
142 catch(std::exception&)
145 // Attempts to put in more than max_size() items should result in a
150 x.resize(x.max_size() - _S_word_bit, false);
151 for(int i = 0; i < _S_word_bit + 1; ++i)
155 catch(std::bad_alloc)
157 catch(std::length_error)
159 catch(std::exception)
165 x.resize(x.max_size() - _S_word_bit, false);
166 x.insert(x.end(), _S_word_bit + 1, false);
169 catch(std::bad_alloc)
171 catch(std::length_error)
173 catch(std::exception)
179 x.resize(x.max_size() - _S_word_bit, false);
180 std::vector<bool> y(_S_word_bit + 1, false);
181 x.insert(x.end(), y.begin(), y.end());
184 catch(std::bad_alloc)
186 catch(std::length_error)
188 catch(std::exception)