1 // Copyright (C) 2007, 2009, 2010, 2012 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 3, 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 COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 23.2.5 class vector<bool> [lib.vector.bool]
20 // { dg-skip-if "" { powerpc64-*-freebsd* } { "*" } { "" } }
21 // { dg-do run { xfail *-*-darwin8.[0-4].* } }
25 #include <testsuite_hooks.h>
28 using std::_GLIBCXX_STD_C::_S_word_bit;
29 #elif defined(_GLIBCXX_PROFILE)
30 using std::_GLIBCXX_STD_C::_S_word_bit;
32 using std::_S_word_bit;
36 check_cap_ge_size(const std::vector<bool>& x)
38 if (x.capacity() < x.size())
39 throw std::logic_error("");
43 check_cap_eq_maxsize(const std::vector<bool>& x)
45 if (x.capacity() != x.max_size())
46 throw std::logic_error("");
52 bool test __attribute__((unused)) = true;
58 x.reserve(x.max_size());
59 check_cap_eq_maxsize(x);
61 catch(std::bad_alloc&)
63 catch(std::exception&)
66 // When doubling is too big, but smaller is sufficient, the resize
67 // should do smaller and be happy. It certainly shouldn't throw
68 // other exceptions or crash.
72 x.resize(x.max_size() / 2 + 1, false);
73 for(int i = 0; i < _S_word_bit; ++i)
77 catch(std::bad_alloc&)
79 catch(std::exception&)
85 x.resize(x.max_size() / 2 + 1, false);
86 x.insert(x.end(), _S_word_bit, false);
89 catch(std::bad_alloc&)
91 catch(std::exception&)
97 x.resize(x.max_size() / 2 + 1, false);
98 std::vector<bool> y(_S_word_bit, false);
99 x.insert(x.end(), y.begin(), y.end());
100 check_cap_ge_size(x);
102 catch(std::bad_alloc&)
104 catch(std::exception&)
107 // These tests are currently only relevant to bool: don't get burned
108 // by the attempt to round up when near the max size.
112 x.resize(x.max_size() - _S_word_bit, false);
113 for(int i = 0; i < _S_word_bit; ++i)
115 check_cap_ge_size(x);
117 catch(std::bad_alloc&)
119 catch(std::exception&)
125 x.resize(x.max_size() - _S_word_bit, false);
126 x.insert(x.end(), _S_word_bit, false);
127 check_cap_ge_size(x);
129 catch(std::bad_alloc&)
131 catch(std::exception&)
137 x.resize(x.max_size() - _S_word_bit, false);
138 std::vector<bool> y(_S_word_bit, false);
139 x.insert(x.end(), y.begin(), y.end());
140 check_cap_ge_size(x);
142 catch(std::bad_alloc&)
144 catch(std::exception&)
147 // Attempts to put in more than max_size() items should result in a
152 x.resize(x.max_size() - _S_word_bit, false);
153 for(int i = 0; i < _S_word_bit + 1; ++i)
157 catch(std::bad_alloc)
159 catch(std::length_error)
161 catch(std::exception)
167 x.resize(x.max_size() - _S_word_bit, false);
168 x.insert(x.end(), _S_word_bit + 1, false);
171 catch(std::bad_alloc)
173 catch(std::length_error)
175 catch(std::exception)
181 x.resize(x.max_size() - _S_word_bit, false);
182 std::vector<bool> y(_S_word_bit + 1, false);
183 x.insert(x.end(), y.begin(), y.end());
186 catch(std::bad_alloc)
188 catch(std::length_error)
190 catch(std::exception)