29 #ifndef _GLIBCXX_DEBUG_MACROS_H
30 #define _GLIBCXX_DEBUG_MACROS_H 1
41 #define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \
42 if (__builtin_expect(!bool(_Cond), false)) \
43 __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
46 #define _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,_Func) \
48 __glibcxx_constexpr_assert(_Cond); \
49 _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func); \
52 #define _GLIBCXX_DEBUG_VERIFY_AT(_Cond,_ErrMsg,_File,_Line) \
53 _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,__PRETTY_FUNCTION__)
55 #define _GLIBCXX_DEBUG_VERIFY(_Cond,_ErrMsg) \
56 _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond, _ErrMsg, __FILE__, __LINE__, \
60 #define __glibcxx_check_valid_range(_First,_Last) \
61 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last), \
62 _M_message(__gnu_debug::__msg_valid_range) \
63 ._M_iterator(_First, #_First) \
64 ._M_iterator(_Last, #_Last))
66 #define __glibcxx_check_valid_range_at(_First,_Last,_File,_Line,_Func) \
67 _GLIBCXX_DEBUG_VERIFY_AT_F(__gnu_debug::__valid_range(_First, _Last), \
68 _M_message(__gnu_debug::__msg_valid_range) \
69 ._M_iterator(_First, #_First) \
70 ._M_iterator(_Last, #_Last), \
73 #define __glibcxx_check_valid_range2(_First,_Last,_Dist) \
74 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last, _Dist), \
75 _M_message(__gnu_debug::__msg_valid_range) \
76 ._M_iterator(_First, #_First) \
77 ._M_iterator(_Last, #_Last))
79 #define __glibcxx_check_valid_constructor_range(_First,_Last) \
80 __gnu_debug::__check_valid_range(_First, _Last, \
81 __FILE__, __LINE__, __PRETTY_FUNCTION__)
84 #define __glibcxx_check_non_empty_range(_First,_Last) \
85 _GLIBCXX_DEBUG_VERIFY(_First != _Last, \
86 _M_message(__gnu_debug::__msg_non_empty_range) \
87 ._M_iterator(_First, #_First) \
88 ._M_iterator(_Last, #_Last))
91 #define __glibcxx_check_can_increment(_First,_Size) \
92 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__can_advance(_First, _Size), \
93 _M_message(__gnu_debug::__msg_iter_subscript_oob) \
94 ._M_iterator(_First, #_First) \
95 ._M_integer(_Size, #_Size))
97 #define __glibcxx_check_can_increment_dist(_First,_Dist,_Way) \
98 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__can_advance(_First, _Dist, _Way), \
99 _M_message(__gnu_debug::__msg_iter_subscript_oob) \
100 ._M_iterator(_First, #_First) \
101 ._M_integer(_Way * _Dist.first, #_Dist))
103 #define __glibcxx_check_can_increment_range(_First1,_Last1,_First2) \
106 typename __gnu_debug::_Distance_traits<__decltype(_First1)>::__type __dist;\
107 _GLIBCXX_DEBUG_VERIFY_AT_F( \
108 __gnu_debug::__valid_range(_First1, _Last1, __dist),\
109 _M_message(__gnu_debug::__msg_valid_range) \
110 ._M_iterator(_First1, #_First1) \
111 ._M_iterator(_Last1, #_Last1), \
112 __FILE__,__LINE__,__PRETTY_FUNCTION__); \
113 _GLIBCXX_DEBUG_VERIFY_AT_F( \
114 __gnu_debug::__can_advance(_First2, __dist, 1), \
115 _M_message(__gnu_debug::__msg_iter_subscript_oob)\
116 ._M_iterator(_First2, #_First2) \
117 ._M_integer(__dist.first), \
118 __FILE__,__LINE__,__PRETTY_FUNCTION__); \
121 #define __glibcxx_check_can_decrement_range(_First1,_Last1,_First2) \
124 typename __gnu_debug::_Distance_traits<__decltype(_First1)>::__type __dist;\
125 _GLIBCXX_DEBUG_VERIFY_AT_F( \
126 __gnu_debug::__valid_range(_First1, _Last1, __dist),\
127 _M_message(__gnu_debug::__msg_valid_range) \
128 ._M_iterator(_First1, #_First1) \
129 ._M_iterator(_Last1, #_Last1), \
130 __FILE__,__LINE__,__PRETTY_FUNCTION__); \
131 _GLIBCXX_DEBUG_VERIFY_AT_F( \
132 __gnu_debug::__can_advance(_First2, __dist, -1), \
133 _M_message(__gnu_debug::__msg_iter_subscript_oob)\
134 ._M_iterator(_First2, #_First2) \
135 ._M_integer(-__dist.first), \
136 __FILE__,__LINE__,__PRETTY_FUNCTION__); \
146 #define __glibcxx_check_insert(_Position) \
147 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \
148 _M_message(__gnu_debug::__msg_insert_singular) \
149 ._M_sequence(*this, "this") \
150 ._M_iterator(_Position, #_Position)); \
151 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
152 _M_message(__gnu_debug::__msg_insert_different) \
153 ._M_sequence(*this, "this") \
154 ._M_iterator(_Position, #_Position))
163 #define __glibcxx_check_insert_after(_Position) \
164 __glibcxx_check_insert(_Position); \
165 _GLIBCXX_DEBUG_VERIFY(!_Position._M_is_end(), \
166 _M_message(__gnu_debug::__msg_insert_after_end) \
167 ._M_sequence(*this, "this") \
168 ._M_iterator(_Position, #_Position))
180 #define __glibcxx_check_insert_range(_Position,_First,_Last,_Dist) \
181 __glibcxx_check_valid_range2(_First,_Last,_Dist); \
182 __glibcxx_check_insert(_Position); \
183 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\
184 _M_message(__gnu_debug::__msg_insert_range_from_self)\
185 ._M_iterator(_First, #_First) \
186 ._M_iterator(_Last, #_Last) \
187 ._M_sequence(*this, "this"))
199 #define __glibcxx_check_insert_range_after(_Position,_First,_Last,_Dist)\
200 __glibcxx_check_valid_range2(_First,_Last,_Dist); \
201 __glibcxx_check_insert_after(_Position); \
202 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\
203 _M_message(__gnu_debug::__msg_insert_range_from_self)\
204 ._M_iterator(_First, #_First) \
205 ._M_iterator(_Last, #_Last) \
206 ._M_sequence(*this, "this"))
212 #define __glibcxx_check_erase(_Position) \
213 _GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(), \
214 _M_message(__gnu_debug::__msg_erase_bad) \
215 ._M_sequence(*this, "this") \
216 ._M_iterator(_Position, #_Position)); \
217 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
218 _M_message(__gnu_debug::__msg_erase_different) \
219 ._M_sequence(*this, "this") \
220 ._M_iterator(_Position, #_Position))
222 #if __cplusplus >= 201103L
223 # define __glibcxx_check_erase2(_CPosition) \
224 _GLIBCXX_DEBUG_VERIFY(_CPosition != _M_base().cend(), \
225 _M_message(__gnu_debug::__msg_erase_bad) \
226 ._M_sequence(*this, "this") \
227 ._M_iterator(_CPosition, #_CPosition));
234 #define __glibcxx_check_erase_after(_Position) \
235 _GLIBCXX_DEBUG_VERIFY(_Position._M_before_dereferenceable(), \
236 _M_message(__gnu_debug::__msg_erase_after_bad) \
237 ._M_sequence(*this, "this") \
238 ._M_iterator(_Position, #_Position)); \
239 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
240 _M_message(__gnu_debug::__msg_erase_different) \
241 ._M_sequence(*this, "this") \
242 ._M_iterator(_Position, #_Position))
248 #define __glibcxx_check_erase_range(_First,_Last) \
249 __glibcxx_check_valid_range(_First,_Last); \
250 _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \
251 _M_message(__gnu_debug::__msg_erase_different) \
252 ._M_sequence(*this, "this") \
253 ._M_iterator(_First, #_First) \
254 ._M_iterator(_Last, #_Last))
260 #define __glibcxx_check_erase_range_after(_First,_Last) \
261 _GLIBCXX_DEBUG_VERIFY(!_First._M_singular() && !_Last._M_singular(), \
262 _M_message(__gnu_debug::__msg_erase_different) \
263 ._M_sequence(*this, "this") \
264 ._M_iterator(_First, #_First) \
265 ._M_iterator(_Last, #_Last)); \
266 _GLIBCXX_DEBUG_VERIFY(_First._M_can_compare(_Last), \
267 _M_message(__gnu_debug::__msg_erase_different) \
268 ._M_sequence(*this, "this") \
269 ._M_iterator(_First, #_First) \
270 ._M_iterator(_Last, #_Last)); \
271 _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \
272 _M_message(__gnu_debug::__msg_erase_different) \
273 ._M_sequence(*this, "this") \
274 ._M_iterator(_First, #_First)); \
275 _GLIBCXX_DEBUG_VERIFY(_First != _Last, \
276 _M_message(__gnu_debug::__msg_valid_range2) \
277 ._M_sequence(*this, "this") \
278 ._M_iterator(_First, #_First) \
279 ._M_iterator(_Last, #_Last)); \
280 _GLIBCXX_DEBUG_VERIFY(_First._M_incrementable(), \
281 _M_message(__gnu_debug::__msg_valid_range2) \
282 ._M_sequence(*this, "this") \
283 ._M_iterator(_First, #_First) \
284 ._M_iterator(_Last, #_Last)); \
285 _GLIBCXX_DEBUG_VERIFY(!_Last._M_is_before_begin(), \
286 _M_message(__gnu_debug::__msg_valid_range2) \
287 ._M_sequence(*this, "this") \
288 ._M_iterator(_First, #_First) \
289 ._M_iterator(_Last, #_Last)) \
292 #define __glibcxx_check_subscript(_N) \
293 _GLIBCXX_DEBUG_VERIFY(_N < this->size(), \
294 _M_message(__gnu_debug::__msg_subscript_oob) \
295 ._M_sequence(*this, "this") \
296 ._M_integer(_N, #_N) \
297 ._M_integer(this->size(), "size"))
300 #define __glibcxx_check_bucket_index(_N) \
301 _GLIBCXX_DEBUG_VERIFY(_N < this->bucket_count(), \
302 _M_message(__gnu_debug::__msg_bucket_index_oob) \
303 ._M_sequence(*this, "this") \
304 ._M_integer(_N, #_N) \
305 ._M_integer(this->bucket_count(), "size"))
308 #define __glibcxx_check_nonempty() \
309 _GLIBCXX_DEBUG_VERIFY(! this->empty(), \
310 _M_message(__gnu_debug::__msg_empty) \
311 ._M_sequence(*this, "this"))
314 #define __glibcxx_check_irreflexive(_First,_Last) \
315 _GLIBCXX_DEBUG_VERIFY(_First == _Last || !(*_First < *_First), \
316 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
317 ._M_iterator_value_type(_First, "< operator type"))
319 #if __cplusplus >= 201103L
320 # define __glibcxx_check_irreflexive2(_First,_Last) \
321 _GLIBCXX_DEBUG_VERIFY(_First == _Last \
322 || __gnu_debug::__is_irreflexive(_First), \
323 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
324 ._M_iterator_value_type(_First, "< operator type"))
326 # define __glibcxx_check_irreflexive2(_First,_Last)
329 #define __glibcxx_check_irreflexive_pred(_First,_Last,_Pred) \
330 _GLIBCXX_DEBUG_VERIFY(_First == _Last || !_Pred(*_First, *_First), \
331 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
332 ._M_instance(_Pred, "functor") \
333 ._M_iterator_value_type(_First, "ordered type"))
335 #if __cplusplus >= 201103L
336 # define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred) \
337 _GLIBCXX_DEBUG_VERIFY(_First == _Last \
338 ||__gnu_debug::__is_irreflexive_pred(_First, _Pred), \
339 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
340 ._M_instance(_Pred, "functor") \
341 ._M_iterator_value_type(_First, "ordered type"))
343 # define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred)
347 #define __glibcxx_check_sorted(_First,_Last) \
348 __glibcxx_check_valid_range(_First,_Last); \
349 __glibcxx_check_irreflexive(_First,_Last); \
350 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
351 __gnu_debug::__base(_First), \
352 __gnu_debug::__base(_Last)), \
353 _M_message(__gnu_debug::__msg_unsorted) \
354 ._M_iterator(_First, #_First) \
355 ._M_iterator(_Last, #_Last))
359 #define __glibcxx_check_sorted_pred(_First,_Last,_Pred) \
360 __glibcxx_check_valid_range(_First,_Last); \
361 __glibcxx_check_irreflexive_pred(_First,_Last,_Pred); \
362 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
363 __gnu_debug::__base(_First), \
364 __gnu_debug::__base(_Last), _Pred), \
365 _M_message(__gnu_debug::__msg_unsorted_pred) \
366 ._M_iterator(_First, #_First) \
367 ._M_iterator(_Last, #_Last) \
371 #define __glibcxx_check_sorted_set(_First1,_Last1,_First2) \
372 __glibcxx_check_valid_range(_First1,_Last1); \
373 _GLIBCXX_DEBUG_VERIFY( \
374 __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1), \
375 __gnu_debug::__base(_Last1), _First2),\
376 _M_message(__gnu_debug::__msg_unsorted) \
377 ._M_iterator(_First1, #_First1) \
378 ._M_iterator(_Last1, #_Last1))
381 #define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred) \
382 __glibcxx_check_valid_range(_First1,_Last1); \
383 _GLIBCXX_DEBUG_VERIFY( \
384 __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1), \
385 __gnu_debug::__base(_Last1), \
387 _M_message(__gnu_debug::__msg_unsorted_pred) \
388 ._M_iterator(_First1, #_First1) \
389 ._M_iterator(_Last1, #_Last1) \
394 #define __glibcxx_check_partitioned_lower(_First,_Last,_Value) \
395 __glibcxx_check_valid_range(_First,_Last); \
396 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower( \
397 __gnu_debug::__base(_First), \
398 __gnu_debug::__base(_Last), _Value), \
399 _M_message(__gnu_debug::__msg_unpartitioned) \
400 ._M_iterator(_First, #_First) \
401 ._M_iterator(_Last, #_Last) \
404 #define __glibcxx_check_partitioned_upper(_First,_Last,_Value) \
405 __glibcxx_check_valid_range(_First,_Last); \
406 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper( \
407 __gnu_debug::__base(_First), \
408 __gnu_debug::__base(_Last), _Value), \
409 _M_message(__gnu_debug::__msg_unpartitioned) \
410 ._M_iterator(_First, #_First) \
411 ._M_iterator(_Last, #_Last) \
416 #define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \
417 __glibcxx_check_valid_range(_First,_Last); \
418 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower( \
419 __gnu_debug::__base(_First), \
420 __gnu_debug::__base(_Last), _Value, _Pred), \
421 _M_message(__gnu_debug::__msg_unpartitioned_pred) \
422 ._M_iterator(_First, #_First) \
423 ._M_iterator(_Last, #_Last) \
429 #define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
430 __glibcxx_check_valid_range(_First,_Last); \
431 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper( \
432 __gnu_debug::__base(_First), \
433 __gnu_debug::__base(_Last), _Value, _Pred), \
434 _M_message(__gnu_debug::__msg_unpartitioned_pred) \
435 ._M_iterator(_First, #_First) \
436 ._M_iterator(_Last, #_Last) \
441 #define __glibcxx_check_heap(_First,_Last) \
442 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \
443 __gnu_debug::__base(_Last)), \
444 _M_message(__gnu_debug::__msg_not_heap) \
445 ._M_iterator(_First, #_First) \
446 ._M_iterator(_Last, #_Last))
450 #define __glibcxx_check_heap_pred(_First,_Last,_Pred) \
451 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \
452 __gnu_debug::__base(_Last), \
454 _M_message(__gnu_debug::__msg_not_heap_pred) \
455 ._M_iterator(_First, #_First) \
456 ._M_iterator(_Last, #_Last) \
460 #define __glibcxx_check_max_load_factor(_F) \
461 _GLIBCXX_DEBUG_VERIFY(_F > 0.0f, \
462 _M_message(__gnu_debug::__msg_valid_load_factor) \
463 ._M_sequence(*this, "this"))
465 #define __glibcxx_check_equal_allocs(_This, _Other) \
466 _GLIBCXX_DEBUG_VERIFY(_This.get_allocator() == _Other.get_allocator(), \
467 _M_message(__gnu_debug::__msg_equal_allocs) \
468 ._M_sequence(_This, "this"))
470 #define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_PEDASSERT(_String != 0)
471 #define __glibcxx_check_string_len(_String,_Len) \
472 _GLIBCXX_DEBUG_PEDASSERT(_String != 0 || _Len == 0)