]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/31370.cc
1 // Copyright (C) 2007, 2009 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-do run { xfail *-*-darwin8.[0-4].* } }
24 #include <testsuite_hooks.h>
26 #ifndef _GLIBCXX_DEBUG
27 using std::_S_word_bit
;
29 using std::_GLIBCXX_STD_D::_S_word_bit
;
33 check_cap_ge_size(const std::vector
<bool>& x
)
35 if (x
.capacity() < x
.size())
36 throw std::logic_error("");
40 check_cap_eq_maxsize(const std::vector
<bool>& x
)
42 if (x
.capacity() != x
.max_size())
43 throw std::logic_error("");
49 bool test
__attribute__((unused
)) = true;
55 x
.reserve(x
.max_size());
56 check_cap_eq_maxsize(x
);
58 catch(std::bad_alloc
&)
60 catch(std::exception
&)
63 // When doubling is too big, but smaller is sufficient, the resize
64 // should do smaller and be happy. It certainly shouldn't throw
65 // other exceptions or crash.
69 x
.resize(x
.max_size() / 2 + 1, false);
70 for(int i
= 0; i
< _S_word_bit
; ++i
)
74 catch(std::bad_alloc
&)
76 catch(std::exception
&)
82 x
.resize(x
.max_size() / 2 + 1, false);
83 x
.insert(x
.end(), _S_word_bit
, false);
86 catch(std::bad_alloc
&)
88 catch(std::exception
&)
94 x
.resize(x
.max_size() / 2 + 1, false);
95 std::vector
<bool> y(_S_word_bit
, false);
96 x
.insert(x
.end(), y
.begin(), y
.end());
99 catch(std::bad_alloc
&)
101 catch(std::exception
&)
104 // These tests are currently only relevant to bool: don't get burned
105 // by the attempt to round up when near the max size.
109 x
.resize(x
.max_size() - _S_word_bit
, false);
110 for(int i
= 0; i
< _S_word_bit
; ++i
)
112 check_cap_ge_size(x
);
114 catch(std::bad_alloc
&)
116 catch(std::exception
&)
122 x
.resize(x
.max_size() - _S_word_bit
, false);
123 x
.insert(x
.end(), _S_word_bit
, false);
124 check_cap_ge_size(x
);
126 catch(std::bad_alloc
&)
128 catch(std::exception
&)
134 x
.resize(x
.max_size() - _S_word_bit
, false);
135 std::vector
<bool> y(_S_word_bit
, false);
136 x
.insert(x
.end(), y
.begin(), y
.end());
137 check_cap_ge_size(x
);
139 catch(std::bad_alloc
&)
141 catch(std::exception
&)
144 // Attempts to put in more than max_size() items should result in a
149 x
.resize(x
.max_size() - _S_word_bit
, false);
150 for(int i
= 0; i
< _S_word_bit
+ 1; ++i
)
154 catch(std::bad_alloc
)
156 catch(std::length_error
)
158 catch(std::exception
)
164 x
.resize(x
.max_size() - _S_word_bit
, false);
165 x
.insert(x
.end(), _S_word_bit
+ 1, false);
168 catch(std::bad_alloc
)
170 catch(std::length_error
)
172 catch(std::exception
)
178 x
.resize(x
.max_size() - _S_word_bit
, false);
179 std::vector
<bool> y(_S_word_bit
+ 1, false);
180 x
.insert(x
.end(), y
.begin(), y
.end());
183 catch(std::bad_alloc
)
185 catch(std::length_error
)
187 catch(std::exception
)