]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/31370.cc
re PR debug/43370 (ICE gen_type_die_with_usage, at dwarf2out.c:14745)
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / bool / modifiers / insert / 31370.cc
CommitLineData
748086b7 1// Copyright (C) 2007, 2009 Free Software Foundation, Inc.
be1088fa
ML
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
748086b7 6// Free Software Foundation; either version 3, or (at your option)
be1088fa
ML
7// any later version.
8
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.
13
14// You should have received a copy of the GNU General Public License along
748086b7
JJ
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
be1088fa
ML
17
18// 23.2.5 class vector<bool> [lib.vector.bool]
19
20// { dg-do run { xfail *-*-darwin8.[0-4].* } }
21
22#include <vector>
23#include <stdexcept>
24#include <testsuite_hooks.h>
25
ece84738
BK
26#ifndef _GLIBCXX_DEBUG
27 using std::_S_word_bit;
28#else
29 using std::_GLIBCXX_STD_D::_S_word_bit;
30#endif
31
be1088fa
ML
32inline void
33check_cap_ge_size(const std::vector<bool>& x)
34{
35 if (x.capacity() < x.size())
36 throw std::logic_error("");
37}
38
39inline void
40check_cap_eq_maxsize(const std::vector<bool>& x)
41{
42 if (x.capacity() != x.max_size())
43 throw std::logic_error("");
44}
45
46// libstdc++/31370
47void test01()
48{
49 bool test __attribute__((unused)) = true;
50 int myexit = 0;
51
52 try
53 {
54 std::vector<bool> x;
55 x.reserve(x.max_size());
56 check_cap_eq_maxsize(x);
57 }
58 catch(std::bad_alloc&)
59 { }
60 catch(std::exception&)
61 { ++myexit; }
62
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.
66 try
67 {
68 std::vector<bool> x;
69 x.resize(x.max_size() / 2 + 1, false);
ece84738 70 for(int i = 0; i < _S_word_bit; ++i)
be1088fa
ML
71 x.push_back(false);
72 check_cap_ge_size(x);
73 }
74 catch(std::bad_alloc&)
75 { }
76 catch(std::exception&)
77 { ++myexit; }
78
79 try
80 {
81 std::vector<bool> x;
82 x.resize(x.max_size() / 2 + 1, false);
ece84738 83 x.insert(x.end(), _S_word_bit, false);
be1088fa
ML
84 check_cap_ge_size(x);
85 }
86 catch(std::bad_alloc&)
87 { }
88 catch(std::exception&)
89 { ++myexit; }
90
91 try
92 {
93 std::vector<bool> x;
94 x.resize(x.max_size() / 2 + 1, false);
ece84738 95 std::vector<bool> y(_S_word_bit, false);
be1088fa
ML
96 x.insert(x.end(), y.begin(), y.end());
97 check_cap_ge_size(x);
98 }
99 catch(std::bad_alloc&)
100 { }
101 catch(std::exception&)
102 { ++myexit; }
103
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.
106 try
107 {
108 std::vector<bool> x;
ece84738
BK
109 x.resize(x.max_size() - _S_word_bit, false);
110 for(int i = 0; i < _S_word_bit; ++i)
be1088fa
ML
111 x.push_back(false);
112 check_cap_ge_size(x);
113 }
114 catch(std::bad_alloc&)
115 { }
116 catch(std::exception&)
117 { ++myexit; }
118
119 try
120 {
121 std::vector<bool> x;
ece84738
BK
122 x.resize(x.max_size() - _S_word_bit, false);
123 x.insert(x.end(), _S_word_bit, false);
be1088fa
ML
124 check_cap_ge_size(x);
125 }
126 catch(std::bad_alloc&)
127 { }
128 catch(std::exception&)
129 { ++myexit; }
130
131 try
132 {
133 std::vector<bool> x;
ece84738
BK
134 x.resize(x.max_size() - _S_word_bit, false);
135 std::vector<bool> y(_S_word_bit, false);
be1088fa
ML
136 x.insert(x.end(), y.begin(), y.end());
137 check_cap_ge_size(x);
138 }
139 catch(std::bad_alloc&)
140 { }
141 catch(std::exception&)
142 { ++myexit; }
143
144 // Attempts to put in more than max_size() items should result in a
145 // length error.
146 try
147 {
148 std::vector<bool> x;
ece84738
BK
149 x.resize(x.max_size() - _S_word_bit, false);
150 for(int i = 0; i < _S_word_bit + 1; ++i)
be1088fa
ML
151 x.push_back(false);
152 ++myexit;
153 }
154 catch(std::bad_alloc)
155 { }
156 catch(std::length_error)
157 { }
158 catch(std::exception)
159 { ++myexit; }
160
161 try
162 {
163 std::vector<bool> x;
ece84738
BK
164 x.resize(x.max_size() - _S_word_bit, false);
165 x.insert(x.end(), _S_word_bit + 1, false);
be1088fa
ML
166 ++myexit;
167 }
168 catch(std::bad_alloc)
169 { }
170 catch(std::length_error)
171 { }
172 catch(std::exception)
173 { ++myexit; }
174
175 try
176 {
177 std::vector<bool> x;
ece84738
BK
178 x.resize(x.max_size() - _S_word_bit, false);
179 std::vector<bool> y(_S_word_bit + 1, false);
be1088fa
ML
180 x.insert(x.end(), y.begin(), y.end());
181 ++myexit;
182 }
183 catch(std::bad_alloc)
184 { }
185 catch(std::length_error)
186 { }
187 catch(std::exception)
188 { ++myexit; }
189
190 VERIFY( !myexit );
191}
192
193int main()
194{
195 test01();
196 return 0;
197}