]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/debug/macros.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / macros.h
CommitLineData
e6dd2a96 1// Debugging support implementation -*- C++ -*-
2
f1717362 3// Copyright (C) 2003-2016 Free Software Foundation, Inc.
e6dd2a96 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
e6dd2a96 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
6bc9506f 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.
e6dd2a96 19
6bc9506f 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/>.
e6dd2a96 24
0e014800 25/** @file debug/macros.h
26 * This file is a GNU debug extension to the Standard C++ Library.
27 */
28
e6dd2a96 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
72117d76 36 * @a correct choice of making them functions) because we need line and
e6dd2a96 37 * file information at the call site, to minimize the distance between
38 * the user error and where the error is reported.
39 *
40 */
2548203e 41#define _GLIBCXX_DEBUG_VERIFY_AT(_Condition,_ErrorMessage,_File,_Line) \
42 do \
10c73e3f 43 { \
e6dd2a96 44 if (! (_Condition)) \
2548203e 45 __gnu_debug::_Error_formatter::_M_at(_File, _Line) \
e6dd2a96 46 ._ErrorMessage._M_error(); \
47 } while (false)
48
2548203e 49#define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage) \
50 _GLIBCXX_DEBUG_VERIFY_AT(_Condition,_ErrorMessage,__FILE__,__LINE__)
51
e6dd2a96 52// Verify that [_First, _Last) forms a valid iterator range.
53#define __glibcxx_check_valid_range(_First,_Last) \
10c73e3f 54_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last), \
55 _M_message(__gnu_debug::__msg_valid_range) \
e6dd2a96 56 ._M_iterator(_First, #_First) \
57 ._M_iterator(_Last, #_Last))
58
d9ba0dd6 59#define __glibcxx_check_valid_range2(_First,_Last,_Dist) \
60_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last, _Dist), \
61 _M_message(__gnu_debug::__msg_valid_range) \
62 ._M_iterator(_First, #_First) \
63 ._M_iterator(_Last, #_Last))
64
4f6cadc5 65// Verify that [_First, _Last) forms a non-empty iterator range.
66#define __glibcxx_check_non_empty_range(_First,_Last) \
67_GLIBCXX_DEBUG_VERIFY(_First != _Last, \
68 _M_message(__gnu_debug::__msg_non_empty_range) \
69 ._M_iterator(_First, #_First) \
70 ._M_iterator(_Last, #_Last))
71
e6dd2a96 72/** Verify that we can insert into *this with the iterator _Position.
73 * Insertion into a container at a specific position requires that
17f663ea 74 * the iterator be nonsingular, either dereferenceable or past-the-end,
75 * and that it reference the sequence we are inserting into. Note that
76 * this macro is only valid when the container is a_Safe_sequence and
77 * the iterator is a _Safe_iterator.
e6dd2a96 78*/
79#define __glibcxx_check_insert(_Position) \
80_GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \
56c44694 81 _M_message(__gnu_debug::__msg_insert_singular) \
e6dd2a96 82 ._M_sequence(*this, "this") \
83 ._M_iterator(_Position, #_Position)); \
84_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
56c44694 85 _M_message(__gnu_debug::__msg_insert_different) \
e6dd2a96 86 ._M_sequence(*this, "this") \
87 ._M_iterator(_Position, #_Position))
88
17f663ea 89/** Verify that we can insert into *this after the iterator _Position.
90 * Insertion into a container after a specific position requires that
91 * the iterator be nonsingular, either dereferenceable or before-begin,
92 * and that it reference the sequence we are inserting into. Note that
93 * this macro is only valid when the container is a_Safe_sequence and
94 * the iterator is a _Safe_iterator.
95*/
96#define __glibcxx_check_insert_after(_Position) \
97__glibcxx_check_insert(_Position); \
98_GLIBCXX_DEBUG_VERIFY(!_Position._M_is_end(), \
99 _M_message(__gnu_debug::__msg_insert_after_end) \
100 ._M_sequence(*this, "this") \
101 ._M_iterator(_Position, #_Position))
102
e6dd2a96 103/** Verify that we can insert the values in the iterator range
104 * [_First, _Last) into *this with the iterator _Position. Insertion
105 * into a container at a specific position requires that the iterator
106 * be nonsingular (i.e., either dereferenceable or past-the-end),
107 * that it reference the sequence we are inserting into, and that the
85f1350d 108 * iterator range [_First, _Last) is a valid (possibly empty)
109 * range which does not reference the sequence we are inserting into.
110 * Note that this macro is only valid when the container is a
56c44694 111 * _Safe_sequence and the _Position iterator is a _Safe_iterator.
e6dd2a96 112*/
d9ba0dd6 113#define __glibcxx_check_insert_range(_Position,_First,_Last,_Dist) \
114__glibcxx_check_valid_range2(_First,_Last,_Dist); \
56c44694 115__glibcxx_check_insert(_Position); \
85f1350d 116_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\
56c44694 117 _M_message(__gnu_debug::__msg_insert_range_from_self)\
118 ._M_iterator(_First, #_First) \
119 ._M_iterator(_Last, #_Last) \
120 ._M_sequence(*this, "this"))
17f663ea 121
122/** Verify that we can insert the values in the iterator range
123 * [_First, _Last) into *this after the iterator _Position. Insertion
124 * into a container after a specific position requires that the iterator
125 * be nonsingular (i.e., either dereferenceable or past-the-end),
126 * that it reference the sequence we are inserting into, and that the
85f1350d 127 * iterator range [_First, _Last) is a valid (possibly empty)
128 * range which does not reference the sequence we are inserting into.
129 * Note that this macro is only valid when the container is a
130 * _Safe_sequence and the _Position iterator is a _Safe_iterator.
17f663ea 131*/
d9ba0dd6 132#define __glibcxx_check_insert_range_after(_Position,_First,_Last,_Dist)\
133 __glibcxx_check_valid_range2(_First,_Last,_Dist); \
85f1350d 134__glibcxx_check_insert_after(_Position); \
135_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\
56c44694 136 _M_message(__gnu_debug::__msg_insert_range_from_self)\
137 ._M_iterator(_First, #_First) \
138 ._M_iterator(_Last, #_Last) \
139 ._M_sequence(*this, "this"))
e6dd2a96 140
141/** Verify that we can erase the element referenced by the iterator
142 * _Position. We can erase the element if the _Position iterator is
143 * dereferenceable and references this sequence.
144*/
145#define __glibcxx_check_erase(_Position) \
146_GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(), \
10c73e3f 147 _M_message(__gnu_debug::__msg_erase_bad) \
e6dd2a96 148 ._M_sequence(*this, "this") \
149 ._M_iterator(_Position, #_Position)); \
150_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
10c73e3f 151 _M_message(__gnu_debug::__msg_erase_different) \
e6dd2a96 152 ._M_sequence(*this, "this") \
153 ._M_iterator(_Position, #_Position))
154
17f663ea 155/** Verify that we can erase the element after the iterator
156 * _Position. We can erase the element if the _Position iterator is
157 * before a dereferenceable one and references this sequence.
158*/
159#define __glibcxx_check_erase_after(_Position) \
160_GLIBCXX_DEBUG_VERIFY(_Position._M_before_dereferenceable(), \
161 _M_message(__gnu_debug::__msg_erase_after_bad) \
162 ._M_sequence(*this, "this") \
163 ._M_iterator(_Position, #_Position)); \
164_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
165 _M_message(__gnu_debug::__msg_erase_different) \
166 ._M_sequence(*this, "this") \
167 ._M_iterator(_Position, #_Position))
168
e6dd2a96 169/** Verify that we can erase the elements in the iterator range
170 * [_First, _Last). We can erase the elements if [_First, _Last) is a
171 * valid iterator range within this sequence.
172*/
173#define __glibcxx_check_erase_range(_First,_Last) \
174__glibcxx_check_valid_range(_First,_Last); \
175_GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \
10c73e3f 176 _M_message(__gnu_debug::__msg_erase_different) \
e6dd2a96 177 ._M_sequence(*this, "this") \
178 ._M_iterator(_First, #_First) \
179 ._M_iterator(_Last, #_Last))
180
17f663ea 181/** Verify that we can erase the elements in the iterator range
182 * (_First, _Last). We can erase the elements if (_First, _Last) is a
183 * valid iterator range within this sequence.
184*/
185#define __glibcxx_check_erase_range_after(_First,_Last) \
186_GLIBCXX_DEBUG_VERIFY(_First._M_can_compare(_Last), \
187 _M_message(__gnu_debug::__msg_erase_different) \
188 ._M_sequence(*this, "this") \
189 ._M_iterator(_First, #_First) \
190 ._M_iterator(_Last, #_Last)); \
191_GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \
192 _M_message(__gnu_debug::__msg_erase_different) \
193 ._M_sequence(*this, "this") \
194 ._M_iterator(_First, #_First)); \
195_GLIBCXX_DEBUG_VERIFY(_First != _Last, \
196 _M_message(__gnu_debug::__msg_valid_range2) \
197 ._M_sequence(*this, "this") \
198 ._M_iterator(_First, #_First) \
199 ._M_iterator(_Last, #_Last)); \
200_GLIBCXX_DEBUG_VERIFY(_First._M_incrementable(), \
201 _M_message(__gnu_debug::__msg_valid_range2) \
202 ._M_sequence(*this, "this") \
203 ._M_iterator(_First, #_First) \
204 ._M_iterator(_Last, #_Last)); \
205_GLIBCXX_DEBUG_VERIFY(!_Last._M_is_before_begin(), \
206 _M_message(__gnu_debug::__msg_valid_range2) \
207 ._M_sequence(*this, "this") \
208 ._M_iterator(_First, #_First) \
209 ._M_iterator(_Last, #_Last)) \
210
e6dd2a96 211// Verify that the subscript _N is less than the container's size.
212#define __glibcxx_check_subscript(_N) \
213_GLIBCXX_DEBUG_VERIFY(_N < this->size(), \
698c853f 214 _M_message(__gnu_debug::__msg_subscript_oob) \
e6dd2a96 215 ._M_sequence(*this, "this") \
216 ._M_integer(_N, #_N) \
217 ._M_integer(this->size(), "size"))
218
698c853f 219// Verify that the bucket _N is less than the container's buckets count.
220#define __glibcxx_check_bucket_index(_N) \
221_GLIBCXX_DEBUG_VERIFY(_N < this->bucket_count(), \
222 _M_message(__gnu_debug::__msg_bucket_index_oob) \
223 ._M_sequence(*this, "this") \
224 ._M_integer(_N, #_N) \
225 ._M_integer(this->bucket_count(), "size"))
226
e6dd2a96 227// Verify that the container is nonempty
228#define __glibcxx_check_nonempty() \
229_GLIBCXX_DEBUG_VERIFY(! this->empty(), \
10c73e3f 230 _M_message(__gnu_debug::__msg_empty) \
e6dd2a96 231 ._M_sequence(*this, "this"))
232
e6dd2a96 233// Verify that the iterator range [_First, _Last) is sorted
234#define __glibcxx_check_sorted(_First,_Last) \
235__glibcxx_check_valid_range(_First,_Last); \
096d86ac 236 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
237 __gnu_debug::__base(_First), \
238 __gnu_debug::__base(_Last)), \
10c73e3f 239 _M_message(__gnu_debug::__msg_unsorted) \
e6dd2a96 240 ._M_iterator(_First, #_First) \
241 ._M_iterator(_Last, #_Last))
242
243/** Verify that the iterator range [_First, _Last) is sorted by the
244 predicate _Pred. */
245#define __glibcxx_check_sorted_pred(_First,_Last,_Pred) \
246__glibcxx_check_valid_range(_First,_Last); \
096d86ac 247_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
248 __gnu_debug::__base(_First), \
249 __gnu_debug::__base(_Last), _Pred), \
10c73e3f 250 _M_message(__gnu_debug::__msg_unsorted_pred) \
e6dd2a96 251 ._M_iterator(_First, #_First) \
252 ._M_iterator(_Last, #_Last) \
253 ._M_string(#_Pred))
254
eb256643 255// Special variant for std::merge, std::includes, std::set_*
256#define __glibcxx_check_sorted_set(_First1,_Last1,_First2) \
257__glibcxx_check_valid_range(_First1,_Last1); \
258_GLIBCXX_DEBUG_VERIFY( \
096d86ac 259 __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1), \
260 __gnu_debug::__base(_Last1), _First2),\
eb256643 261 _M_message(__gnu_debug::__msg_unsorted) \
262 ._M_iterator(_First1, #_First1) \
263 ._M_iterator(_Last1, #_Last1))
264
265// Likewise with a _Pred.
266#define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred) \
267__glibcxx_check_valid_range(_First1,_Last1); \
268_GLIBCXX_DEBUG_VERIFY( \
096d86ac 269 __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1), \
270 __gnu_debug::__base(_Last1), \
271 _First2, _Pred), \
eb256643 272 _M_message(__gnu_debug::__msg_unsorted_pred) \
273 ._M_iterator(_First1, #_First1) \
274 ._M_iterator(_Last1, #_Last1) \
275 ._M_string(#_Pred))
276
e6dd2a96 277/** Verify that the iterator range [_First, _Last) is partitioned
278 w.r.t. the value _Value. */
beece52b 279#define __glibcxx_check_partitioned_lower(_First,_Last,_Value) \
e6dd2a96 280__glibcxx_check_valid_range(_First,_Last); \
096d86ac 281_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower( \
282 __gnu_debug::__base(_First), \
283 __gnu_debug::__base(_Last), _Value), \
10c73e3f 284 _M_message(__gnu_debug::__msg_unpartitioned) \
e6dd2a96 285 ._M_iterator(_First, #_First) \
286 ._M_iterator(_Last, #_Last) \
287 ._M_string(#_Value))
288
beece52b 289#define __glibcxx_check_partitioned_upper(_First,_Last,_Value) \
290__glibcxx_check_valid_range(_First,_Last); \
096d86ac 291_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper( \
292 __gnu_debug::__base(_First), \
293 __gnu_debug::__base(_Last), _Value), \
beece52b 294 _M_message(__gnu_debug::__msg_unpartitioned) \
295 ._M_iterator(_First, #_First) \
296 ._M_iterator(_Last, #_Last) \
297 ._M_string(#_Value))
298
299/** Verify that the iterator range [_First, _Last) is partitioned
300 w.r.t. the value _Value and predicate _Pred. */
301#define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \
302__glibcxx_check_valid_range(_First,_Last); \
096d86ac 303_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower( \
304 __gnu_debug::__base(_First), \
305 __gnu_debug::__base(_Last), _Value, _Pred), \
beece52b 306 _M_message(__gnu_debug::__msg_unpartitioned_pred) \
307 ._M_iterator(_First, #_First) \
308 ._M_iterator(_Last, #_Last) \
309 ._M_string(#_Pred) \
310 ._M_string(#_Value))
311
e6dd2a96 312/** Verify that the iterator range [_First, _Last) is partitioned
313 w.r.t. the value _Value and predicate _Pred. */
beece52b 314#define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
e6dd2a96 315__glibcxx_check_valid_range(_First,_Last); \
096d86ac 316_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper( \
317 __gnu_debug::__base(_First), \
318 __gnu_debug::__base(_Last), _Value, _Pred), \
10c73e3f 319 _M_message(__gnu_debug::__msg_unpartitioned_pred) \
e6dd2a96 320 ._M_iterator(_First, #_First) \
321 ._M_iterator(_Last, #_Last) \
322 ._M_string(#_Pred) \
323 ._M_string(#_Value))
324
325// Verify that the iterator range [_First, _Last) is a heap
326#define __glibcxx_check_heap(_First,_Last) \
c3a6a085 327 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \
328 __gnu_debug::__base(_Last)), \
10c73e3f 329 _M_message(__gnu_debug::__msg_not_heap) \
e6dd2a96 330 ._M_iterator(_First, #_First) \
331 ._M_iterator(_Last, #_Last))
332
333/** Verify that the iterator range [_First, _Last) is a heap
334 w.r.t. the predicate _Pred. */
335#define __glibcxx_check_heap_pred(_First,_Last,_Pred) \
c3a6a085 336 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \
337 __gnu_debug::__base(_Last), \
338 _Pred), \
10c73e3f 339 _M_message(__gnu_debug::__msg_not_heap_pred) \
e6dd2a96 340 ._M_iterator(_First, #_First) \
341 ._M_iterator(_Last, #_Last) \
342 ._M_string(#_Pred))
343
2b336fc3 344// Verify that the container is not self move assigned
345#define __glibcxx_check_self_move_assign(_Other) \
346_GLIBCXX_DEBUG_VERIFY(this != &_Other, \
de4b5856 347 _M_message(__gnu_debug::__msg_self_move_assign) \
348 ._M_sequence(*this, "this"))
349
85f1350d 350// Verify that load factor is positive
de4b5856 351#define __glibcxx_check_max_load_factor(_F) \
352_GLIBCXX_DEBUG_VERIFY(_F > 0.0f, \
353 _M_message(__gnu_debug::__msg_valid_load_factor) \
2b336fc3 354 ._M_sequence(*this, "this"))
355
b25436b0 356#define __glibcxx_check_equal_allocs(_This, _Other) \
357_GLIBCXX_DEBUG_VERIFY(_This.get_allocator() == _Other.get_allocator(), \
b41dd924 358 _M_message(__gnu_debug::__msg_equal_allocs) \
b25436b0 359 ._M_sequence(_This, "this"))
b41dd924 360
d9ba0dd6 361#define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_PEDASSERT(_String != 0)
362#define __glibcxx_check_string_len(_String,_Len) \
363 _GLIBCXX_DEBUG_PEDASSERT(_String != 0 || _Len == 0)
e6dd2a96 364
39ba392e 365// Verify that a predicate is irreflexive
366#define __glibcxx_check_irreflexive(_First,_Last) \
367 _GLIBCXX_DEBUG_VERIFY(_First == _Last || !(*_First < *_First), \
368 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
369 ._M_iterator_value_type(_First, "< operator type"))
370
371#if __cplusplus >= 201103L
372# define __glibcxx_check_irreflexive2(_First,_Last) \
373 _GLIBCXX_DEBUG_VERIFY(_First == _Last \
374 || __gnu_debug::__is_irreflexive(_First), \
375 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
376 ._M_iterator_value_type(_First, "< operator type"))
377#else
378# define __glibcxx_check_irreflexive2(_First,_Last)
379#endif
380
381#define __glibcxx_check_irreflexive_pred(_First,_Last,_Pred) \
382 _GLIBCXX_DEBUG_VERIFY(_First == _Last || !_Pred(*_First, *_First), \
383 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
384 ._M_instance(_Pred, "functor") \
385 ._M_iterator_value_type(_First, "ordered type"))
386
387#if __cplusplus >= 201103L
388# define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred) \
389 _GLIBCXX_DEBUG_VERIFY(_First == _Last \
390 ||__gnu_debug::__is_irreflexive_pred(_First, _Pred), \
391 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
392 ._M_instance(_Pred, "functor") \
393 ._M_iterator_value_type(_First, "ordered type"))
394#else
395# define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred)
396#endif
397
e6dd2a96 398#endif