29 #ifndef _GLIBCXX_DEBUG_MACROS_H
30 #define _GLIBCXX_DEBUG_MACROS_H 1
42 # define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \
43 if (__builtin_is_constant_evaluated()) \
47 __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
50 # define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \
52 __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
56 #define _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,_Func) \
59 _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func); \
62 #define _GLIBCXX_DEBUG_VERIFY_AT(_Cond,_ErrMsg,_File,_Line) \
63 _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,__PRETTY_FUNCTION__)
65 #define _GLIBCXX_DEBUG_VERIFY(_Cond,_ErrMsg) \
66 _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond, _ErrMsg, __FILE__, __LINE__, \
70 #define __glibcxx_check_valid_range(_First,_Last) \
71 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last), \
72 _M_message(__gnu_debug::__msg_valid_range) \
73 ._M_iterator(_First, #_First) \
74 ._M_iterator(_Last, #_Last))
76 #define __glibcxx_check_valid_range_at(_First,_Last,_File,_Line,_Func) \
77 _GLIBCXX_DEBUG_VERIFY_AT_F(__gnu_debug::__valid_range(_First, _Last), \
78 _M_message(__gnu_debug::__msg_valid_range) \
79 ._M_iterator(_First, #_First) \
80 ._M_iterator(_Last, #_Last), \
83 #define __glibcxx_check_valid_range2(_First,_Last,_Dist) \
84 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last, _Dist), \
85 _M_message(__gnu_debug::__msg_valid_range) \
86 ._M_iterator(_First, #_First) \
87 ._M_iterator(_Last, #_Last))
89 #define __glibcxx_check_valid_constructor_range(_First,_Last) \
90 __gnu_debug::__check_valid_range(_First, _Last, \
91 __FILE__, __LINE__, __PRETTY_FUNCTION__)
94 #define __glibcxx_check_non_empty_range(_First,_Last) \
95 _GLIBCXX_DEBUG_VERIFY(_First != _Last, \
96 _M_message(__gnu_debug::__msg_non_empty_range) \
97 ._M_iterator(_First, #_First) \
98 ._M_iterator(_Last, #_Last))
101 #define __glibcxx_check_can_increment(_First,_Size) \
102 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__can_advance(_First, _Size), \
103 _M_message(__gnu_debug::__msg_iter_subscript_oob) \
104 ._M_iterator(_First, #_First) \
105 ._M_integer(_Size, #_Size))
107 #define __glibcxx_check_can_increment_dist(_First,_Dist,_Way) \
108 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__can_advance(_First, _Dist, _Way), \
109 _M_message(__gnu_debug::__msg_iter_subscript_oob) \
110 ._M_iterator(_First, #_First) \
111 ._M_integer(_Way * _Dist.first, #_Dist))
113 #define __glibcxx_check_can_increment_range(_First1,_Last1,_First2) \
116 typename __gnu_debug::_Distance_traits<__decltype(_First1)>::__type __dist;\
117 _GLIBCXX_DEBUG_VERIFY_COND_AT( \
118 __gnu_debug::__valid_range(_First1, _Last1, __dist),\
119 _M_message(__gnu_debug::__msg_valid_range) \
120 ._M_iterator(_First1, #_First1) \
121 ._M_iterator(_Last1, #_Last1), \
122 __FILE__,__LINE__,__PRETTY_FUNCTION__); \
123 _GLIBCXX_DEBUG_VERIFY_COND_AT( \
124 __gnu_debug::__can_advance(_First2, __dist, 1), \
125 _M_message(__gnu_debug::__msg_iter_subscript_oob)\
126 ._M_iterator(_First2, #_First2) \
127 ._M_integer(__dist.first), \
128 __FILE__,__LINE__,__PRETTY_FUNCTION__); \
131 #define __glibcxx_check_can_decrement_range(_First1,_Last1,_First2) \
134 typename __gnu_debug::_Distance_traits<__decltype(_First1)>::__type __dist;\
135 _GLIBCXX_DEBUG_VERIFY_COND_AT( \
136 __gnu_debug::__valid_range(_First1, _Last1, __dist),\
137 _M_message(__gnu_debug::__msg_valid_range) \
138 ._M_iterator(_First1, #_First1) \
139 ._M_iterator(_Last1, #_Last1), \
140 __FILE__,__LINE__,__PRETTY_FUNCTION__); \
141 _GLIBCXX_DEBUG_VERIFY_COND_AT( \
142 __gnu_debug::__can_advance(_First2, __dist, -1), \
143 _M_message(__gnu_debug::__msg_iter_subscript_oob)\
144 ._M_iterator(_First2, #_First2) \
145 ._M_integer(-__dist.first), \
146 __FILE__,__LINE__,__PRETTY_FUNCTION__); \
156 #define __glibcxx_check_insert(_Position) \
157 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \
158 _M_message(__gnu_debug::__msg_insert_singular) \
159 ._M_sequence(*this, "this") \
160 ._M_iterator(_Position, #_Position)); \
161 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
162 _M_message(__gnu_debug::__msg_insert_different) \
163 ._M_sequence(*this, "this") \
164 ._M_iterator(_Position, #_Position))
173 #define __glibcxx_check_insert_after(_Position) \
174 __glibcxx_check_insert(_Position); \
175 _GLIBCXX_DEBUG_VERIFY(!_Position._M_is_end(), \
176 _M_message(__gnu_debug::__msg_insert_after_end) \
177 ._M_sequence(*this, "this") \
178 ._M_iterator(_Position, #_Position))
190 #define __glibcxx_check_insert_range(_Position,_First,_Last,_Dist) \
191 __glibcxx_check_valid_range2(_First,_Last,_Dist); \
192 __glibcxx_check_insert(_Position); \
193 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\
194 _M_message(__gnu_debug::__msg_insert_range_from_self)\
195 ._M_iterator(_First, #_First) \
196 ._M_iterator(_Last, #_Last) \
197 ._M_sequence(*this, "this"))
209 #define __glibcxx_check_insert_range_after(_Position,_First,_Last,_Dist)\
210 __glibcxx_check_valid_range2(_First,_Last,_Dist); \
211 __glibcxx_check_insert_after(_Position); \
212 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\
213 _M_message(__gnu_debug::__msg_insert_range_from_self)\
214 ._M_iterator(_First, #_First) \
215 ._M_iterator(_Last, #_Last) \
216 ._M_sequence(*this, "this"))
222 #define __glibcxx_check_erase(_Position) \
223 _GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(), \
224 _M_message(__gnu_debug::__msg_erase_bad) \
225 ._M_sequence(*this, "this") \
226 ._M_iterator(_Position, #_Position)); \
227 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
228 _M_message(__gnu_debug::__msg_erase_different) \
229 ._M_sequence(*this, "this") \
230 ._M_iterator(_Position, #_Position))
236 #define __glibcxx_check_erase_after(_Position) \
237 _GLIBCXX_DEBUG_VERIFY(_Position._M_before_dereferenceable(), \
238 _M_message(__gnu_debug::__msg_erase_after_bad) \
239 ._M_sequence(*this, "this") \
240 ._M_iterator(_Position, #_Position)); \
241 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
242 _M_message(__gnu_debug::__msg_erase_different) \
243 ._M_sequence(*this, "this") \
244 ._M_iterator(_Position, #_Position))
250 #define __glibcxx_check_erase_range(_First,_Last) \
251 __glibcxx_check_valid_range(_First,_Last); \
252 _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \
253 _M_message(__gnu_debug::__msg_erase_different) \
254 ._M_sequence(*this, "this") \
255 ._M_iterator(_First, #_First) \
256 ._M_iterator(_Last, #_Last))
262 #define __glibcxx_check_erase_range_after(_First,_Last) \
263 _GLIBCXX_DEBUG_VERIFY(_First._M_can_compare(_Last), \
264 _M_message(__gnu_debug::__msg_erase_different) \
265 ._M_sequence(*this, "this") \
266 ._M_iterator(_First, #_First) \
267 ._M_iterator(_Last, #_Last)); \
268 _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \
269 _M_message(__gnu_debug::__msg_erase_different) \
270 ._M_sequence(*this, "this") \
271 ._M_iterator(_First, #_First)); \
272 _GLIBCXX_DEBUG_VERIFY(_First != _Last, \
273 _M_message(__gnu_debug::__msg_valid_range2) \
274 ._M_sequence(*this, "this") \
275 ._M_iterator(_First, #_First) \
276 ._M_iterator(_Last, #_Last)); \
277 _GLIBCXX_DEBUG_VERIFY(_First._M_incrementable(), \
278 _M_message(__gnu_debug::__msg_valid_range2) \
279 ._M_sequence(*this, "this") \
280 ._M_iterator(_First, #_First) \
281 ._M_iterator(_Last, #_Last)); \
282 _GLIBCXX_DEBUG_VERIFY(!_Last._M_is_before_begin(), \
283 _M_message(__gnu_debug::__msg_valid_range2) \
284 ._M_sequence(*this, "this") \
285 ._M_iterator(_First, #_First) \
286 ._M_iterator(_Last, #_Last)) \
289 #define __glibcxx_check_subscript(_N) \
290 _GLIBCXX_DEBUG_VERIFY(_N < this->size(), \
291 _M_message(__gnu_debug::__msg_subscript_oob) \
292 ._M_sequence(*this, "this") \
293 ._M_integer(_N, #_N) \
294 ._M_integer(this->size(), "size"))
297 #define __glibcxx_check_bucket_index(_N) \
298 _GLIBCXX_DEBUG_VERIFY(_N < this->bucket_count(), \
299 _M_message(__gnu_debug::__msg_bucket_index_oob) \
300 ._M_sequence(*this, "this") \
301 ._M_integer(_N, #_N) \
302 ._M_integer(this->bucket_count(), "size"))
305 #define __glibcxx_check_nonempty() \
306 _GLIBCXX_DEBUG_VERIFY(! this->empty(), \
307 _M_message(__gnu_debug::__msg_empty) \
308 ._M_sequence(*this, "this"))
311 #define __glibcxx_check_irreflexive(_First,_Last) \
312 _GLIBCXX_DEBUG_VERIFY(_First == _Last || !(*_First < *_First), \
313 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
314 ._M_iterator_value_type(_First, "< operator type"))
316 #if __cplusplus >= 201103L
317 # define __glibcxx_check_irreflexive2(_First,_Last) \
318 _GLIBCXX_DEBUG_VERIFY(_First == _Last \
319 || __gnu_debug::__is_irreflexive(_First), \
320 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
321 ._M_iterator_value_type(_First, "< operator type"))
323 # define __glibcxx_check_irreflexive2(_First,_Last)
326 #define __glibcxx_check_irreflexive_pred(_First,_Last,_Pred) \
327 _GLIBCXX_DEBUG_VERIFY(_First == _Last || !_Pred(*_First, *_First), \
328 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
329 ._M_instance(_Pred, "functor") \
330 ._M_iterator_value_type(_First, "ordered type"))
332 #if __cplusplus >= 201103L
333 # define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred) \
334 _GLIBCXX_DEBUG_VERIFY(_First == _Last \
335 ||__gnu_debug::__is_irreflexive_pred(_First, _Pred), \
336 _M_message(__gnu_debug::__msg_irreflexive_ordering) \
337 ._M_instance(_Pred, "functor") \
338 ._M_iterator_value_type(_First, "ordered type"))
340 # define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred)
344 #define __glibcxx_check_sorted(_First,_Last) \
345 __glibcxx_check_valid_range(_First,_Last); \
346 __glibcxx_check_irreflexive(_First,_Last); \
347 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
348 __gnu_debug::__base(_First), \
349 __gnu_debug::__base(_Last)), \
350 _M_message(__gnu_debug::__msg_unsorted) \
351 ._M_iterator(_First, #_First) \
352 ._M_iterator(_Last, #_Last))
356 #define __glibcxx_check_sorted_pred(_First,_Last,_Pred) \
357 __glibcxx_check_valid_range(_First,_Last); \
358 __glibcxx_check_irreflexive_pred(_First,_Last,_Pred); \
359 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
360 __gnu_debug::__base(_First), \
361 __gnu_debug::__base(_Last), _Pred), \
362 _M_message(__gnu_debug::__msg_unsorted_pred) \
363 ._M_iterator(_First, #_First) \
364 ._M_iterator(_Last, #_Last) \
368 #define __glibcxx_check_sorted_set(_First1,_Last1,_First2) \
369 __glibcxx_check_valid_range(_First1,_Last1); \
370 _GLIBCXX_DEBUG_VERIFY( \
371 __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1), \
372 __gnu_debug::__base(_Last1), _First2),\
373 _M_message(__gnu_debug::__msg_unsorted) \
374 ._M_iterator(_First1, #_First1) \
375 ._M_iterator(_Last1, #_Last1))
378 #define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred) \
379 __glibcxx_check_valid_range(_First1,_Last1); \
380 _GLIBCXX_DEBUG_VERIFY( \
381 __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1), \
382 __gnu_debug::__base(_Last1), \
384 _M_message(__gnu_debug::__msg_unsorted_pred) \
385 ._M_iterator(_First1, #_First1) \
386 ._M_iterator(_Last1, #_Last1) \
391 #define __glibcxx_check_partitioned_lower(_First,_Last,_Value) \
392 __glibcxx_check_valid_range(_First,_Last); \
393 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower( \
394 __gnu_debug::__base(_First), \
395 __gnu_debug::__base(_Last), _Value), \
396 _M_message(__gnu_debug::__msg_unpartitioned) \
397 ._M_iterator(_First, #_First) \
398 ._M_iterator(_Last, #_Last) \
401 #define __glibcxx_check_partitioned_upper(_First,_Last,_Value) \
402 __glibcxx_check_valid_range(_First,_Last); \
403 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper( \
404 __gnu_debug::__base(_First), \
405 __gnu_debug::__base(_Last), _Value), \
406 _M_message(__gnu_debug::__msg_unpartitioned) \
407 ._M_iterator(_First, #_First) \
408 ._M_iterator(_Last, #_Last) \
413 #define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \
414 __glibcxx_check_valid_range(_First,_Last); \
415 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower( \
416 __gnu_debug::__base(_First), \
417 __gnu_debug::__base(_Last), _Value, _Pred), \
418 _M_message(__gnu_debug::__msg_unpartitioned_pred) \
419 ._M_iterator(_First, #_First) \
420 ._M_iterator(_Last, #_Last) \
426 #define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
427 __glibcxx_check_valid_range(_First,_Last); \
428 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper( \
429 __gnu_debug::__base(_First), \
430 __gnu_debug::__base(_Last), _Value, _Pred), \
431 _M_message(__gnu_debug::__msg_unpartitioned_pred) \
432 ._M_iterator(_First, #_First) \
433 ._M_iterator(_Last, #_Last) \
438 #define __glibcxx_check_heap(_First,_Last) \
439 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \
440 __gnu_debug::__base(_Last)), \
441 _M_message(__gnu_debug::__msg_not_heap) \
442 ._M_iterator(_First, #_First) \
443 ._M_iterator(_Last, #_Last))
447 #define __glibcxx_check_heap_pred(_First,_Last,_Pred) \
448 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(__gnu_debug::__base(_First), \
449 __gnu_debug::__base(_Last), \
451 _M_message(__gnu_debug::__msg_not_heap_pred) \
452 ._M_iterator(_First, #_First) \
453 ._M_iterator(_Last, #_Last) \
457 #define __glibcxx_check_self_move_assign(_Other) \
458 _GLIBCXX_DEBUG_VERIFY(this != &_Other, \
459 _M_message(__gnu_debug::__msg_self_move_assign) \
460 ._M_sequence(*this, "this"))
463 #define __glibcxx_check_max_load_factor(_F) \
464 _GLIBCXX_DEBUG_VERIFY(_F > 0.0f, \
465 _M_message(__gnu_debug::__msg_valid_load_factor) \
466 ._M_sequence(*this, "this"))
468 #define __glibcxx_check_equal_allocs(_This, _Other) \
469 _GLIBCXX_DEBUG_VERIFY(_This.get_allocator() == _Other.get_allocator(), \
470 _M_message(__gnu_debug::__msg_equal_allocs) \
471 ._M_sequence(_This, "this"))
473 #define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_PEDASSERT(_String != 0)
474 #define __glibcxx_check_string_len(_String,_Len) \
475 _GLIBCXX_DEBUG_PEDASSERT(_String != 0 || _Len == 0)