]>
Commit | Line | Data |
---|---|---|
d2763ab5 BK |
1 | // Debugging support implementation -*- C++ -*- |
2 | ||
405feeb8 | 3 | // Copyright (C) 2003-2013 Free Software Foundation, Inc. |
d2763ab5 BK |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
d2763ab5 BK |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
d2763ab5 | 19 | |
748086b7 JJ |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
d2763ab5 | 24 | |
78a53887 BK |
25 | /** @file debug/macros.h |
26 | * This file is a GNU debug extension to the Standard C++ Library. | |
27 | */ | |
28 | ||
d2763ab5 BK |
29 | #ifndef _GLIBCXX_DEBUG_MACROS_H |
30 | #define _GLIBCXX_DEBUG_MACROS_H 1 | |
31 | ||
32 | /** | |
33 | * Macros used by the implementation to verify certain | |
34 | * properties. These macros may only be used directly by the debug | |
35 | * wrappers. Note that these are macros (instead of the more obviously | |
2a60a9f6 | 36 | * @a correct choice of making them functions) because we need line and |
d2763ab5 BK |
37 | * file information at the call site, to minimize the distance between |
38 | * the user error and where the error is reported. | |
39 | * | |
40 | */ | |
f5886803 FD |
41 | #define _GLIBCXX_DEBUG_VERIFY_AT(_Condition,_ErrorMessage,_File,_Line) \ |
42 | do \ | |
45f388bb | 43 | { \ |
d2763ab5 | 44 | if (! (_Condition)) \ |
f5886803 | 45 | __gnu_debug::_Error_formatter::_M_at(_File, _Line) \ |
d2763ab5 BK |
46 | ._ErrorMessage._M_error(); \ |
47 | } while (false) | |
48 | ||
f5886803 FD |
49 | #define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage) \ |
50 | _GLIBCXX_DEBUG_VERIFY_AT(_Condition,_ErrorMessage,__FILE__,__LINE__) | |
51 | ||
d2763ab5 BK |
52 | // Verify that [_First, _Last) forms a valid iterator range. |
53 | #define __glibcxx_check_valid_range(_First,_Last) \ | |
45f388bb BK |
54 | _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last), \ |
55 | _M_message(__gnu_debug::__msg_valid_range) \ | |
d2763ab5 BK |
56 | ._M_iterator(_First, #_First) \ |
57 | ._M_iterator(_Last, #_Last)) | |
58 | ||
a8028a3e JW |
59 | // Verify that [_First, _Last) forms a non-empty iterator range. |
60 | #define __glibcxx_check_non_empty_range(_First,_Last) \ | |
61 | _GLIBCXX_DEBUG_VERIFY(_First != _Last, \ | |
62 | _M_message(__gnu_debug::__msg_non_empty_range) \ | |
63 | ._M_iterator(_First, #_First) \ | |
64 | ._M_iterator(_Last, #_Last)) | |
65 | ||
d2763ab5 BK |
66 | /** Verify that we can insert into *this with the iterator _Position. |
67 | * Insertion into a container at a specific position requires that | |
b8b4301e PC |
68 | * the iterator be nonsingular, either dereferenceable or past-the-end, |
69 | * and that it reference the sequence we are inserting into. Note that | |
70 | * this macro is only valid when the container is a_Safe_sequence and | |
71 | * the iterator is a _Safe_iterator. | |
d2763ab5 BK |
72 | */ |
73 | #define __glibcxx_check_insert(_Position) \ | |
74 | _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \ | |
5720787a | 75 | _M_message(__gnu_debug::__msg_insert_singular) \ |
d2763ab5 BK |
76 | ._M_sequence(*this, "this") \ |
77 | ._M_iterator(_Position, #_Position)); \ | |
78 | _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ | |
5720787a | 79 | _M_message(__gnu_debug::__msg_insert_different) \ |
d2763ab5 BK |
80 | ._M_sequence(*this, "this") \ |
81 | ._M_iterator(_Position, #_Position)) | |
82 | ||
b8b4301e PC |
83 | /** Verify that we can insert into *this after the iterator _Position. |
84 | * Insertion into a container after a specific position requires that | |
85 | * the iterator be nonsingular, either dereferenceable or before-begin, | |
86 | * and that it reference the sequence we are inserting into. Note that | |
87 | * this macro is only valid when the container is a_Safe_sequence and | |
88 | * the iterator is a _Safe_iterator. | |
89 | */ | |
90 | #define __glibcxx_check_insert_after(_Position) \ | |
91 | __glibcxx_check_insert(_Position); \ | |
92 | _GLIBCXX_DEBUG_VERIFY(!_Position._M_is_end(), \ | |
93 | _M_message(__gnu_debug::__msg_insert_after_end) \ | |
94 | ._M_sequence(*this, "this") \ | |
95 | ._M_iterator(_Position, #_Position)) | |
96 | ||
d2763ab5 BK |
97 | /** Verify that we can insert the values in the iterator range |
98 | * [_First, _Last) into *this with the iterator _Position. Insertion | |
99 | * into a container at a specific position requires that the iterator | |
100 | * be nonsingular (i.e., either dereferenceable or past-the-end), | |
101 | * that it reference the sequence we are inserting into, and that the | |
102 | * iterator range [_First, Last) is a valid (possibly empty) | |
103 | * range. Note that this macro is only valid when the container is a | |
5720787a | 104 | * _Safe_sequence and the _Position iterator is a _Safe_iterator. |
d2763ab5 BK |
105 | */ |
106 | #define __glibcxx_check_insert_range(_Position,_First,_Last) \ | |
107 | __glibcxx_check_valid_range(_First,_Last); \ | |
5720787a FD |
108 | __glibcxx_check_insert(_Position); \ |
109 | _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First),\ | |
110 | _M_message(__gnu_debug::__msg_insert_range_from_self)\ | |
111 | ._M_iterator(_First, #_First) \ | |
112 | ._M_iterator(_Last, #_Last) \ | |
113 | ._M_sequence(*this, "this")) | |
b8b4301e PC |
114 | |
115 | /** Verify that we can insert the values in the iterator range | |
116 | * [_First, _Last) into *this after the iterator _Position. Insertion | |
117 | * into a container after a specific position requires that the iterator | |
118 | * be nonsingular (i.e., either dereferenceable or past-the-end), | |
119 | * that it reference the sequence we are inserting into, and that the | |
120 | * iterator range [_First, Last) is a valid (possibly empty) | |
121 | * range. Note that this macro is only valid when the container is a | |
122 | * _Safe_sequence and the iterator is a _Safe_iterator. | |
123 | * | |
124 | * @todo We would like to be able to check for noninterference of | |
125 | * _Position and the range [_First, _Last), but that can't (in | |
126 | * general) be done. | |
127 | */ | |
128 | #define __glibcxx_check_insert_range_after(_Position,_First,_Last) \ | |
129 | __glibcxx_check_valid_range(_First,_Last); \ | |
5720787a FD |
130 | __glibcxx_check_insert_after(_Position); \ |
131 | _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First),\ | |
132 | _M_message(__gnu_debug::__msg_insert_range_from_self)\ | |
133 | ._M_iterator(_First, #_First) \ | |
134 | ._M_iterator(_Last, #_Last) \ | |
135 | ._M_sequence(*this, "this")) | |
d2763ab5 BK |
136 | |
137 | /** Verify that we can erase the element referenced by the iterator | |
138 | * _Position. We can erase the element if the _Position iterator is | |
139 | * dereferenceable and references this sequence. | |
140 | */ | |
141 | #define __glibcxx_check_erase(_Position) \ | |
142 | _GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(), \ | |
45f388bb | 143 | _M_message(__gnu_debug::__msg_erase_bad) \ |
d2763ab5 BK |
144 | ._M_sequence(*this, "this") \ |
145 | ._M_iterator(_Position, #_Position)); \ | |
146 | _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ | |
45f388bb | 147 | _M_message(__gnu_debug::__msg_erase_different) \ |
d2763ab5 BK |
148 | ._M_sequence(*this, "this") \ |
149 | ._M_iterator(_Position, #_Position)) | |
150 | ||
b8b4301e PC |
151 | /** Verify that we can erase the element after the iterator |
152 | * _Position. We can erase the element if the _Position iterator is | |
153 | * before a dereferenceable one and references this sequence. | |
154 | */ | |
155 | #define __glibcxx_check_erase_after(_Position) \ | |
156 | _GLIBCXX_DEBUG_VERIFY(_Position._M_before_dereferenceable(), \ | |
157 | _M_message(__gnu_debug::__msg_erase_after_bad) \ | |
158 | ._M_sequence(*this, "this") \ | |
159 | ._M_iterator(_Position, #_Position)); \ | |
160 | _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ | |
161 | _M_message(__gnu_debug::__msg_erase_different) \ | |
162 | ._M_sequence(*this, "this") \ | |
163 | ._M_iterator(_Position, #_Position)) | |
164 | ||
d2763ab5 BK |
165 | /** Verify that we can erase the elements in the iterator range |
166 | * [_First, _Last). We can erase the elements if [_First, _Last) is a | |
167 | * valid iterator range within this sequence. | |
168 | */ | |
169 | #define __glibcxx_check_erase_range(_First,_Last) \ | |
170 | __glibcxx_check_valid_range(_First,_Last); \ | |
171 | _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \ | |
45f388bb | 172 | _M_message(__gnu_debug::__msg_erase_different) \ |
d2763ab5 BK |
173 | ._M_sequence(*this, "this") \ |
174 | ._M_iterator(_First, #_First) \ | |
175 | ._M_iterator(_Last, #_Last)) | |
176 | ||
b8b4301e PC |
177 | /** Verify that we can erase the elements in the iterator range |
178 | * (_First, _Last). We can erase the elements if (_First, _Last) is a | |
179 | * valid iterator range within this sequence. | |
180 | */ | |
181 | #define __glibcxx_check_erase_range_after(_First,_Last) \ | |
182 | _GLIBCXX_DEBUG_VERIFY(_First._M_can_compare(_Last), \ | |
183 | _M_message(__gnu_debug::__msg_erase_different) \ | |
184 | ._M_sequence(*this, "this") \ | |
185 | ._M_iterator(_First, #_First) \ | |
186 | ._M_iterator(_Last, #_Last)); \ | |
187 | _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \ | |
188 | _M_message(__gnu_debug::__msg_erase_different) \ | |
189 | ._M_sequence(*this, "this") \ | |
190 | ._M_iterator(_First, #_First)); \ | |
191 | _GLIBCXX_DEBUG_VERIFY(_First != _Last, \ | |
192 | _M_message(__gnu_debug::__msg_valid_range2) \ | |
193 | ._M_sequence(*this, "this") \ | |
194 | ._M_iterator(_First, #_First) \ | |
195 | ._M_iterator(_Last, #_Last)); \ | |
196 | _GLIBCXX_DEBUG_VERIFY(_First._M_incrementable(), \ | |
197 | _M_message(__gnu_debug::__msg_valid_range2) \ | |
198 | ._M_sequence(*this, "this") \ | |
199 | ._M_iterator(_First, #_First) \ | |
200 | ._M_iterator(_Last, #_Last)); \ | |
201 | _GLIBCXX_DEBUG_VERIFY(!_Last._M_is_before_begin(), \ | |
202 | _M_message(__gnu_debug::__msg_valid_range2) \ | |
203 | ._M_sequence(*this, "this") \ | |
204 | ._M_iterator(_First, #_First) \ | |
205 | ._M_iterator(_Last, #_Last)) \ | |
206 | ||
d2763ab5 BK |
207 | // Verify that the subscript _N is less than the container's size. |
208 | #define __glibcxx_check_subscript(_N) \ | |
209 | _GLIBCXX_DEBUG_VERIFY(_N < this->size(), \ | |
7181e991 | 210 | _M_message(__gnu_debug::__msg_subscript_oob) \ |
d2763ab5 BK |
211 | ._M_sequence(*this, "this") \ |
212 | ._M_integer(_N, #_N) \ | |
213 | ._M_integer(this->size(), "size")) | |
214 | ||
7181e991 FD |
215 | // Verify that the bucket _N is less than the container's buckets count. |
216 | #define __glibcxx_check_bucket_index(_N) \ | |
217 | _GLIBCXX_DEBUG_VERIFY(_N < this->bucket_count(), \ | |
218 | _M_message(__gnu_debug::__msg_bucket_index_oob) \ | |
219 | ._M_sequence(*this, "this") \ | |
220 | ._M_integer(_N, #_N) \ | |
221 | ._M_integer(this->bucket_count(), "size")) | |
222 | ||
d2763ab5 BK |
223 | // Verify that the container is nonempty |
224 | #define __glibcxx_check_nonempty() \ | |
225 | _GLIBCXX_DEBUG_VERIFY(! this->empty(), \ | |
45f388bb | 226 | _M_message(__gnu_debug::__msg_empty) \ |
d2763ab5 BK |
227 | ._M_sequence(*this, "this")) |
228 | ||
d2763ab5 BK |
229 | // Verify that the iterator range [_First, _Last) is sorted |
230 | #define __glibcxx_check_sorted(_First,_Last) \ | |
231 | __glibcxx_check_valid_range(_First,_Last); \ | |
45f388bb BK |
232 | _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last), \ |
233 | _M_message(__gnu_debug::__msg_unsorted) \ | |
d2763ab5 BK |
234 | ._M_iterator(_First, #_First) \ |
235 | ._M_iterator(_Last, #_Last)) | |
236 | ||
237 | /** Verify that the iterator range [_First, _Last) is sorted by the | |
238 | predicate _Pred. */ | |
239 | #define __glibcxx_check_sorted_pred(_First,_Last,_Pred) \ | |
240 | __glibcxx_check_valid_range(_First,_Last); \ | |
45f388bb BK |
241 | _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last, _Pred), \ |
242 | _M_message(__gnu_debug::__msg_unsorted_pred) \ | |
d2763ab5 BK |
243 | ._M_iterator(_First, #_First) \ |
244 | ._M_iterator(_Last, #_Last) \ | |
245 | ._M_string(#_Pred)) | |
246 | ||
a4c07f2d PC |
247 | // Special variant for std::merge, std::includes, std::set_* |
248 | #define __glibcxx_check_sorted_set(_First1,_Last1,_First2) \ | |
249 | __glibcxx_check_valid_range(_First1,_Last1); \ | |
250 | _GLIBCXX_DEBUG_VERIFY( \ | |
251 | __gnu_debug::__check_sorted_set(_First1, _Last1, _First2), \ | |
252 | _M_message(__gnu_debug::__msg_unsorted) \ | |
253 | ._M_iterator(_First1, #_First1) \ | |
254 | ._M_iterator(_Last1, #_Last1)) | |
255 | ||
256 | // Likewise with a _Pred. | |
257 | #define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred) \ | |
258 | __glibcxx_check_valid_range(_First1,_Last1); \ | |
259 | _GLIBCXX_DEBUG_VERIFY( \ | |
260 | __gnu_debug::__check_sorted_set(_First1, _Last1, _First2, _Pred), \ | |
261 | _M_message(__gnu_debug::__msg_unsorted_pred) \ | |
262 | ._M_iterator(_First1, #_First1) \ | |
263 | ._M_iterator(_Last1, #_Last1) \ | |
264 | ._M_string(#_Pred)) | |
265 | ||
d2763ab5 BK |
266 | /** Verify that the iterator range [_First, _Last) is partitioned |
267 | w.r.t. the value _Value. */ | |
f5ad3163 | 268 | #define __glibcxx_check_partitioned_lower(_First,_Last,_Value) \ |
d2763ab5 | 269 | __glibcxx_check_valid_range(_First,_Last); \ |
f5ad3163 | 270 | _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \ |
3cbc7af0 | 271 | _Value), \ |
45f388bb | 272 | _M_message(__gnu_debug::__msg_unpartitioned) \ |
d2763ab5 BK |
273 | ._M_iterator(_First, #_First) \ |
274 | ._M_iterator(_Last, #_Last) \ | |
275 | ._M_string(#_Value)) | |
276 | ||
f5ad3163 PC |
277 | #define __glibcxx_check_partitioned_upper(_First,_Last,_Value) \ |
278 | __glibcxx_check_valid_range(_First,_Last); \ | |
279 | _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \ | |
280 | _Value), \ | |
281 | _M_message(__gnu_debug::__msg_unpartitioned) \ | |
282 | ._M_iterator(_First, #_First) \ | |
283 | ._M_iterator(_Last, #_Last) \ | |
284 | ._M_string(#_Value)) | |
285 | ||
286 | /** Verify that the iterator range [_First, _Last) is partitioned | |
287 | w.r.t. the value _Value and predicate _Pred. */ | |
288 | #define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \ | |
289 | __glibcxx_check_valid_range(_First,_Last); \ | |
290 | _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \ | |
291 | _Value, _Pred), \ | |
292 | _M_message(__gnu_debug::__msg_unpartitioned_pred) \ | |
293 | ._M_iterator(_First, #_First) \ | |
294 | ._M_iterator(_Last, #_Last) \ | |
295 | ._M_string(#_Pred) \ | |
296 | ._M_string(#_Value)) | |
297 | ||
d2763ab5 BK |
298 | /** Verify that the iterator range [_First, _Last) is partitioned |
299 | w.r.t. the value _Value and predicate _Pred. */ | |
f5ad3163 | 300 | #define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \ |
d2763ab5 | 301 | __glibcxx_check_valid_range(_First,_Last); \ |
f5ad3163 | 302 | _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \ |
d2763ab5 | 303 | _Value, _Pred), \ |
45f388bb | 304 | _M_message(__gnu_debug::__msg_unpartitioned_pred) \ |
d2763ab5 BK |
305 | ._M_iterator(_First, #_First) \ |
306 | ._M_iterator(_Last, #_Last) \ | |
307 | ._M_string(#_Pred) \ | |
308 | ._M_string(#_Value)) | |
309 | ||
310 | // Verify that the iterator range [_First, _Last) is a heap | |
311 | #define __glibcxx_check_heap(_First,_Last) \ | |
0545ebf2 FD |
312 | _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \ |
313 | __gnu_debug::__base(_Last)), \ | |
45f388bb | 314 | _M_message(__gnu_debug::__msg_not_heap) \ |
d2763ab5 BK |
315 | ._M_iterator(_First, #_First) \ |
316 | ._M_iterator(_Last, #_Last)) | |
317 | ||
318 | /** Verify that the iterator range [_First, _Last) is a heap | |
319 | w.r.t. the predicate _Pred. */ | |
320 | #define __glibcxx_check_heap_pred(_First,_Last,_Pred) \ | |
0545ebf2 FD |
321 | _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \ |
322 | __gnu_debug::__base(_Last), \ | |
323 | _Pred), \ | |
45f388bb | 324 | _M_message(__gnu_debug::__msg_not_heap_pred) \ |
d2763ab5 BK |
325 | ._M_iterator(_First, #_First) \ |
326 | ._M_iterator(_Last, #_Last) \ | |
327 | ._M_string(#_Pred)) | |
328 | ||
739fd6a6 PC |
329 | // Verify that the container is not self move assigned |
330 | #define __glibcxx_check_self_move_assign(_Other) \ | |
331 | _GLIBCXX_DEBUG_VERIFY(this != &_Other, \ | |
14cbb5d8 FD |
332 | _M_message(__gnu_debug::__msg_self_move_assign) \ |
333 | ._M_sequence(*this, "this")) | |
334 | ||
335 | // Verify that load factor is position | |
336 | #define __glibcxx_check_max_load_factor(_F) \ | |
337 | _GLIBCXX_DEBUG_VERIFY(_F > 0.0f, \ | |
338 | _M_message(__gnu_debug::__msg_valid_load_factor) \ | |
739fd6a6 PC |
339 | ._M_sequence(*this, "this")) |
340 | ||
5720787a | 341 | #define __glibcxx_check_equal_allocs(_Other) \ |
e77c9aed JW |
342 | _GLIBCXX_DEBUG_VERIFY(this->get_allocator() == _Other.get_allocator(), \ |
343 | _M_message(__gnu_debug::__msg_equal_allocs) \ | |
344 | ._M_sequence(*this, "this")) | |
345 | ||
d2763ab5 BK |
346 | #ifdef _GLIBCXX_DEBUG_PEDANTIC |
347 | # define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0) | |
348 | # define __glibcxx_check_string_len(_String,_Len) \ | |
349 | _GLIBCXX_DEBUG_ASSERT(_String != 0 || _Len == 0) | |
350 | #else | |
351 | # define __glibcxx_check_string(_String) | |
352 | # define __glibcxx_check_string_len(_String,_Len) | |
353 | #endif | |
354 | ||
355 | #endif |