]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/31370.cc
1 // Copyright (C) 2007-2017 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 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-do run { xfail *-*-darwin8.[0-4].* } }
21 // { dg-skip-if "" { powerpc64-*-freebsd* } }
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("");
57 x
.reserve(x
.max_size());
58 check_cap_eq_maxsize(x
);
60 catch(std::bad_alloc
&)
62 catch(std::exception
&)
65 // When doubling is too big, but smaller is sufficient, the resize
66 // should do smaller and be happy. It certainly shouldn't throw
67 // other exceptions or crash.
71 x
.resize(x
.max_size() / 2 + 1, false);
72 for(int i
= 0; i
< _S_word_bit
; ++i
)
76 catch(std::bad_alloc
&)
78 catch(std::exception
&)
84 x
.resize(x
.max_size() / 2 + 1, false);
85 x
.insert(x
.end(), _S_word_bit
, false);
88 catch(std::bad_alloc
&)
90 catch(std::exception
&)
96 x
.resize(x
.max_size() / 2 + 1, false);
97 std::vector
<bool> y(_S_word_bit
, false);
98 x
.insert(x
.end(), y
.begin(), y
.end());
101 catch(std::bad_alloc
&)
103 catch(std::exception
&)
106 // These tests are currently only relevant to bool: don't get burned
107 // by the attempt to round up when near the max size.
111 x
.resize(x
.max_size() - _S_word_bit
, false);
112 for(int i
= 0; i
< _S_word_bit
; ++i
)
114 check_cap_ge_size(x
);
116 catch(std::bad_alloc
&)
118 catch(std::exception
&)
124 x
.resize(x
.max_size() - _S_word_bit
, false);
125 x
.insert(x
.end(), _S_word_bit
, false);
126 check_cap_ge_size(x
);
128 catch(std::bad_alloc
&)
130 catch(std::exception
&)
136 x
.resize(x
.max_size() - _S_word_bit
, false);
137 std::vector
<bool> y(_S_word_bit
, false);
138 x
.insert(x
.end(), y
.begin(), y
.end());
139 check_cap_ge_size(x
);
141 catch(std::bad_alloc
&)
143 catch(std::exception
&)
146 // Attempts to put in more than max_size() items should result in a
151 x
.resize(x
.max_size() - _S_word_bit
, false);
152 for(int i
= 0; i
< _S_word_bit
+ 1; ++i
)
156 catch(std::bad_alloc
)
158 catch(std::length_error
)
160 catch(std::exception
)
166 x
.resize(x
.max_size() - _S_word_bit
, false);
167 x
.insert(x
.end(), _S_word_bit
+ 1, false);
170 catch(std::bad_alloc
)
172 catch(std::length_error
)
174 catch(std::exception
)
180 x
.resize(x
.max_size() - _S_word_bit
, false);
181 std::vector
<bool> y(_S_word_bit
+ 1, false);
182 x
.insert(x
.end(), y
.begin(), y
.end());
185 catch(std::bad_alloc
)
187 catch(std::length_error
)
189 catch(std::exception
)