]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/debug/macros.h
re PR c++/84588 (internal compiler error: Segmentation fault (contains_struct_check()))
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / macros.h
CommitLineData
d2763ab5
BK
1// Debugging support implementation -*- C++ -*-
2
85ec4feb 3// Copyright (C) 2003-2018 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
24167c42
FD
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
a8028a3e
JW
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
d2763ab5
BK
72/** Verify that we can insert into *this with the iterator _Position.
73 * Insertion into a container at a specific position requires that
b8b4301e
PC
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.
d2763ab5
BK
78*/
79#define __glibcxx_check_insert(_Position) \
80_GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \
5720787a 81 _M_message(__gnu_debug::__msg_insert_singular) \
d2763ab5
BK
82 ._M_sequence(*this, "this") \
83 ._M_iterator(_Position, #_Position)); \
84_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
5720787a 85 _M_message(__gnu_debug::__msg_insert_different) \
d2763ab5
BK
86 ._M_sequence(*this, "this") \
87 ._M_iterator(_Position, #_Position))
88
b8b4301e
PC
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
d2763ab5
BK
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
72d1f255
JW
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
5720787a 111 * _Safe_sequence and the _Position iterator is a _Safe_iterator.
d2763ab5 112*/
24167c42
FD
113#define __glibcxx_check_insert_range(_Position,_First,_Last,_Dist) \
114__glibcxx_check_valid_range2(_First,_Last,_Dist); \
5720787a 115__glibcxx_check_insert(_Position); \
72d1f255 116_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\
5720787a
FD
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"))
b8b4301e
PC
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
72d1f255
JW
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.
b8b4301e 131*/
24167c42
FD
132#define __glibcxx_check_insert_range_after(_Position,_First,_Last,_Dist)\
133 __glibcxx_check_valid_range2(_First,_Last,_Dist); \
72d1f255
JW
134__glibcxx_check_insert_after(_Position); \
135_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\
5720787a
FD
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"))
d2763ab5
BK
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(), \
45f388bb 147 _M_message(__gnu_debug::__msg_erase_bad) \
d2763ab5
BK
148 ._M_sequence(*this, "this") \
149 ._M_iterator(_Position, #_Position)); \
150_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
45f388bb 151 _M_message(__gnu_debug::__msg_erase_different) \
d2763ab5
BK
152 ._M_sequence(*this, "this") \
153 ._M_iterator(_Position, #_Position))
154
b8b4301e
PC
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
d2763ab5
BK
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), \
45f388bb 176 _M_message(__gnu_debug::__msg_erase_different) \
d2763ab5
BK
177 ._M_sequence(*this, "this") \
178 ._M_iterator(_First, #_First) \
179 ._M_iterator(_Last, #_Last))
180
b8b4301e
PC
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
d2763ab5
BK
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(), \
7181e991 214 _M_message(__gnu_debug::__msg_subscript_oob) \
d2763ab5
BK
215 ._M_sequence(*this, "this") \
216 ._M_integer(_N, #_N) \
217 ._M_integer(this->size(), "size"))
218
7181e991
FD
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
d2763ab5
BK
227// Verify that the container is nonempty
228#define __glibcxx_check_nonempty() \
229_GLIBCXX_DEBUG_VERIFY(! this->empty(), \
45f388bb 230 _M_message(__gnu_debug::__msg_empty) \
d2763ab5
BK
231 ._M_sequence(*this, "this"))
232
d2763ab5
BK
233// Verify that the iterator range [_First, _Last) is sorted
234#define __glibcxx_check_sorted(_First,_Last) \
235__glibcxx_check_valid_range(_First,_Last); \
8915a229
FD
236 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
237 __gnu_debug::__base(_First), \
238 __gnu_debug::__base(_Last)), \
45f388bb 239 _M_message(__gnu_debug::__msg_unsorted) \
d2763ab5
BK
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); \
8915a229
FD
247_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
248 __gnu_debug::__base(_First), \
249 __gnu_debug::__base(_Last), _Pred), \
45f388bb 250 _M_message(__gnu_debug::__msg_unsorted_pred) \
d2763ab5
BK
251 ._M_iterator(_First, #_First) \
252 ._M_iterator(_Last, #_Last) \
253 ._M_string(#_Pred))
254
a4c07f2d
PC
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( \
8915a229
FD
259 __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1), \
260 __gnu_debug::__base(_Last1), _First2),\
a4c07f2d
PC
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( \
8915a229
FD
269 __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1), \
270 __gnu_debug::__base(_Last1), \
271 _First2, _Pred), \
a4c07f2d
PC
272 _M_message(__gnu_debug::__msg_unsorted_pred) \
273 ._M_iterator(_First1, #_First1) \
274 ._M_iterator(_Last1, #_Last1) \
275 ._M_string(#_Pred))
276
d2763ab5
BK
277/** Verify that the iterator range [_First, _Last) is partitioned
278 w.r.t. the value _Value. */
f5ad3163 279#define __glibcxx_check_partitioned_lower(_First,_Last,_Value) \
d2763ab5 280__glibcxx_check_valid_range(_First,_Last); \
8915a229
FD
281_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower( \
282 __gnu_debug::__base(_First), \
283 __gnu_debug::__base(_Last), _Value), \
45f388bb 284 _M_message(__gnu_debug::__msg_unpartitioned) \
d2763ab5
BK
285 ._M_iterator(_First, #_First) \
286 ._M_iterator(_Last, #_Last) \
287 ._M_string(#_Value))
288
f5ad3163
PC
289#define __glibcxx_check_partitioned_upper(_First,_Last,_Value) \
290__glibcxx_check_valid_range(_First,_Last); \
8915a229
FD
291_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper( \
292 __gnu_debug::__base(_First), \
293 __gnu_debug::__base(_Last), _Value), \
f5ad3163
PC
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); \
8915a229
FD
303_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower( \
304 __gnu_debug::__base(_First), \
305 __gnu_debug::__base(_Last), _Value, _Pred), \
f5ad3163
PC
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
d2763ab5
BK
312/** Verify that the iterator range [_First, _Last) is partitioned
313 w.r.t. the value _Value and predicate _Pred. */
f5ad3163 314#define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
d2763ab5 315__glibcxx_check_valid_range(_First,_Last); \
8915a229
FD
316_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper( \
317 __gnu_debug::__base(_First), \
318 __gnu_debug::__base(_Last), _Value, _Pred), \
45f388bb 319 _M_message(__gnu_debug::__msg_unpartitioned_pred) \
d2763ab5
BK
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) \
0545ebf2
FD
327 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \
328 __gnu_debug::__base(_Last)), \
45f388bb 329 _M_message(__gnu_debug::__msg_not_heap) \
d2763ab5
BK
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) \
0545ebf2
FD
336 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \
337 __gnu_debug::__base(_Last), \
338 _Pred), \
45f388bb 339 _M_message(__gnu_debug::__msg_not_heap_pred) \
d2763ab5
BK
340 ._M_iterator(_First, #_First) \
341 ._M_iterator(_Last, #_Last) \
342 ._M_string(#_Pred))
343
739fd6a6
PC
344// Verify that the container is not self move assigned
345#define __glibcxx_check_self_move_assign(_Other) \
346_GLIBCXX_DEBUG_VERIFY(this != &_Other, \
14cbb5d8
FD
347 _M_message(__gnu_debug::__msg_self_move_assign) \
348 ._M_sequence(*this, "this"))
349
72d1f255 350// Verify that load factor is positive
14cbb5d8
FD
351#define __glibcxx_check_max_load_factor(_F) \
352_GLIBCXX_DEBUG_VERIFY(_F > 0.0f, \
353 _M_message(__gnu_debug::__msg_valid_load_factor) \
739fd6a6
PC
354 ._M_sequence(*this, "this"))
355
15ee1a77
FD
356#define __glibcxx_check_equal_allocs(_This, _Other) \
357_GLIBCXX_DEBUG_VERIFY(_This.get_allocator() == _Other.get_allocator(), \
e77c9aed 358 _M_message(__gnu_debug::__msg_equal_allocs) \
15ee1a77 359 ._M_sequence(_This, "this"))
e77c9aed 360
24167c42
FD
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)
d2763ab5 364
630a286a
FD
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
d2763ab5 398#endif