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