Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / bool / modifiers / insert / 31370.cc
blob14334512151bf03c6d46f29971a59c84bca0dadc
1 // Copyright (C) 2007-2013 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even 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].* } }
23 #include <vector>
24 #include <stdexcept>
25 #include <testsuite_hooks.h>
27 #ifdef _GLIBCXX_DEBUG
28 using std::_GLIBCXX_STD_C::_S_word_bit;
29 #elif defined(_GLIBCXX_PROFILE)
30 using std::_GLIBCXX_STD_C::_S_word_bit;
31 #else
32 using std::_S_word_bit;
33 #endif
35 inline void
36 check_cap_ge_size(const std::vector<bool>& x)
38 if (x.capacity() < x.size())
39 throw std::logic_error("");
42 inline void
43 check_cap_eq_maxsize(const std::vector<bool>& x)
45 if (x.capacity() != x.max_size())
46 throw std::logic_error("");
49 // libstdc++/31370
50 void test01()
52 bool test __attribute__((unused)) = true;
53 int myexit = 0;
55 try
57 std::vector<bool> x;
58 x.reserve(x.max_size());
59 check_cap_eq_maxsize(x);
61 catch(std::bad_alloc&)
62 { }
63 catch(std::exception&)
64 { ++myexit; }
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.
69 try
71 std::vector<bool> x;
72 x.resize(x.max_size() / 2 + 1, false);
73 for(int i = 0; i < _S_word_bit; ++i)
74 x.push_back(false);
75 check_cap_ge_size(x);
77 catch(std::bad_alloc&)
78 { }
79 catch(std::exception&)
80 { ++myexit; }
82 try
84 std::vector<bool> x;
85 x.resize(x.max_size() / 2 + 1, false);
86 x.insert(x.end(), _S_word_bit, false);
87 check_cap_ge_size(x);
89 catch(std::bad_alloc&)
90 { }
91 catch(std::exception&)
92 { ++myexit; }
94 try
96 std::vector<bool> x;
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&)
105 { ++myexit; }
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.
111 std::vector<bool> x;
112 x.resize(x.max_size() - _S_word_bit, false);
113 for(int i = 0; i < _S_word_bit; ++i)
114 x.push_back(false);
115 check_cap_ge_size(x);
117 catch(std::bad_alloc&)
119 catch(std::exception&)
120 { ++myexit; }
124 std::vector<bool> x;
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&)
132 { ++myexit; }
136 std::vector<bool> x;
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&)
145 { ++myexit; }
147 // Attempts to put in more than max_size() items should result in a
148 // length error.
151 std::vector<bool> x;
152 x.resize(x.max_size() - _S_word_bit, false);
153 for(int i = 0; i < _S_word_bit + 1; ++i)
154 x.push_back(false);
155 ++myexit;
157 catch(std::bad_alloc)
159 catch(std::length_error)
161 catch(std::exception)
162 { ++myexit; }
166 std::vector<bool> x;
167 x.resize(x.max_size() - _S_word_bit, false);
168 x.insert(x.end(), _S_word_bit + 1, false);
169 ++myexit;
171 catch(std::bad_alloc)
173 catch(std::length_error)
175 catch(std::exception)
176 { ++myexit; }
180 std::vector<bool> x;
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());
184 ++myexit;
186 catch(std::bad_alloc)
188 catch(std::length_error)
190 catch(std::exception)
191 { ++myexit; }
193 VERIFY( !myexit );
196 int main()
198 test01();
199 return 0;