1951a39d68df598db08dfced8b4707755864a0492Ying Wang// Debugging support implementation -*- C++ -*-
2951a39d68df598db08dfced8b4707755864a0492Ying Wang
343f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4951a39d68df598db08dfced8b4707755864a0492Ying Wang// Free Software Foundation, Inc.
5951a39d68df598db08dfced8b4707755864a0492Ying Wang//
6951a39d68df598db08dfced8b4707755864a0492Ying Wang// This file is part of the GNU ISO C++ Library.  This library is free
7951a39d68df598db08dfced8b4707755864a0492Ying Wang// software; you can redistribute it and/or modify it under the
8951a39d68df598db08dfced8b4707755864a0492Ying Wang// terms of the GNU General Public License as published by the
9951a39d68df598db08dfced8b4707755864a0492Ying Wang// Free Software Foundation; either version 3, or (at your option)
10951a39d68df598db08dfced8b4707755864a0492Ying Wang// any later version.
11951a39d68df598db08dfced8b4707755864a0492Ying Wang
12951a39d68df598db08dfced8b4707755864a0492Ying Wang// This library is distributed in the hope that it will be useful,
13951a39d68df598db08dfced8b4707755864a0492Ying Wang// but WITHOUT ANY WARRANTY; without even the implied warranty of
14951a39d68df598db08dfced8b4707755864a0492Ying Wang// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15951a39d68df598db08dfced8b4707755864a0492Ying Wang// GNU General Public License for more details.
16951a39d68df598db08dfced8b4707755864a0492Ying Wang
17951a39d68df598db08dfced8b4707755864a0492Ying Wang// Under Section 7 of GPL version 3, you are granted additional
18951a39d68df598db08dfced8b4707755864a0492Ying Wang// permissions described in the GCC Runtime Library Exception, version
19951a39d68df598db08dfced8b4707755864a0492Ying Wang// 3.1, as published by the Free Software Foundation.
20951a39d68df598db08dfced8b4707755864a0492Ying Wang
21951a39d68df598db08dfced8b4707755864a0492Ying Wang// You should have received a copy of the GNU General Public License and
22951a39d68df598db08dfced8b4707755864a0492Ying Wang// a copy of the GCC Runtime Library Exception along with this program;
23951a39d68df598db08dfced8b4707755864a0492Ying Wang// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24951a39d68df598db08dfced8b4707755864a0492Ying Wang// <http://www.gnu.org/licenses/>.
25951a39d68df598db08dfced8b4707755864a0492Ying Wang
26951a39d68df598db08dfced8b4707755864a0492Ying Wang/** @file debug/macros.h
27951a39d68df598db08dfced8b4707755864a0492Ying Wang *  This file is a GNU debug extension to the Standard C++ Library.
28951a39d68df598db08dfced8b4707755864a0492Ying Wang */
29951a39d68df598db08dfced8b4707755864a0492Ying Wang
30951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifndef _GLIBCXX_DEBUG_MACROS_H
31951a39d68df598db08dfced8b4707755864a0492Ying Wang#define _GLIBCXX_DEBUG_MACROS_H 1
32951a39d68df598db08dfced8b4707755864a0492Ying Wang
33951a39d68df598db08dfced8b4707755864a0492Ying Wang/**
34951a39d68df598db08dfced8b4707755864a0492Ying Wang * Macros used by the implementation to verify certain
35951a39d68df598db08dfced8b4707755864a0492Ying Wang * properties. These macros may only be used directly by the debug
36951a39d68df598db08dfced8b4707755864a0492Ying Wang * wrappers. Note that these are macros (instead of the more obviously
3743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh * @a correct choice of making them functions) because we need line and
38951a39d68df598db08dfced8b4707755864a0492Ying Wang * file information at the call site, to minimize the distance between
39951a39d68df598db08dfced8b4707755864a0492Ying Wang * the user error and where the error is reported.
40951a39d68df598db08dfced8b4707755864a0492Ying Wang *
41951a39d68df598db08dfced8b4707755864a0492Ying Wang */
42951a39d68df598db08dfced8b4707755864a0492Ying Wang#define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage)		        \
43951a39d68df598db08dfced8b4707755864a0492Ying Wang  do 									\
44951a39d68df598db08dfced8b4707755864a0492Ying Wang  {									\
45951a39d68df598db08dfced8b4707755864a0492Ying Wang    if (! (_Condition))							\
46951a39d68df598db08dfced8b4707755864a0492Ying Wang      __gnu_debug::_Error_formatter::_M_at(__FILE__, __LINE__)	        \
47951a39d68df598db08dfced8b4707755864a0492Ying Wang	  ._ErrorMessage._M_error();					\
48951a39d68df598db08dfced8b4707755864a0492Ying Wang  } while (false)
49951a39d68df598db08dfced8b4707755864a0492Ying Wang
50951a39d68df598db08dfced8b4707755864a0492Ying Wang// Verify that [_First, _Last) forms a valid iterator range.
51951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_valid_range(_First,_Last)			\
52951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last),	\
53951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_valid_range)	\
54951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_First, #_First)			\
55951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last))
56951a39d68df598db08dfced8b4707755864a0492Ying Wang
57951a39d68df598db08dfced8b4707755864a0492Ying Wang/** Verify that we can insert into *this with the iterator _Position.
58951a39d68df598db08dfced8b4707755864a0492Ying Wang *  Insertion into a container at a specific position requires that
5943f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  the iterator be nonsingular, either dereferenceable or past-the-end,
6043f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  and that it reference the sequence we are inserting into. Note that
6143f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  this macro is only valid when the container is a_Safe_sequence and
6243f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  the iterator is a _Safe_iterator.
63951a39d68df598db08dfced8b4707755864a0492Ying Wang*/
64951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_insert(_Position)				\
65951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),				\
66951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_insert_singular) \
67951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_sequence(*this, "this")			\
68951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Position, #_Position));		\
69951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),			\
70951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_insert_different) \
71951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_sequence(*this, "this")			\
72951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Position, #_Position))
73951a39d68df598db08dfced8b4707755864a0492Ying Wang
7443f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh/** Verify that we can insert into *this after the iterator _Position.
7543f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  Insertion into a container after a specific position requires that
7643f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  the iterator be nonsingular, either dereferenceable or before-begin,
7743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  and that it reference the sequence we are inserting into. Note that
7843f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  this macro is only valid when the container is a_Safe_sequence and
7943f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  the iterator is a _Safe_iterator.
8043f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh*/
8143f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh#define __glibcxx_check_insert_after(_Position)				\
8243f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh__glibcxx_check_insert(_Position);					\
8343f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh_GLIBCXX_DEBUG_VERIFY(!_Position._M_is_end(),				\
8443f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      _M_message(__gnu_debug::__msg_insert_after_end)	\
8543f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_sequence(*this, "this")			\
8643f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_Position, #_Position))
8743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh
88951a39d68df598db08dfced8b4707755864a0492Ying Wang/** Verify that we can insert the values in the iterator range
89951a39d68df598db08dfced8b4707755864a0492Ying Wang *  [_First, _Last) into *this with the iterator _Position.  Insertion
90951a39d68df598db08dfced8b4707755864a0492Ying Wang *  into a container at a specific position requires that the iterator
91951a39d68df598db08dfced8b4707755864a0492Ying Wang *  be nonsingular (i.e., either dereferenceable or past-the-end),
92951a39d68df598db08dfced8b4707755864a0492Ying Wang *  that it reference the sequence we are inserting into, and that the
93951a39d68df598db08dfced8b4707755864a0492Ying Wang *  iterator range [_First, Last) is a valid (possibly empty)
94951a39d68df598db08dfced8b4707755864a0492Ying Wang *  range. Note that this macro is only valid when the container is a
95951a39d68df598db08dfced8b4707755864a0492Ying Wang *  _Safe_sequence and the iterator is a _Safe_iterator.
96951a39d68df598db08dfced8b4707755864a0492Ying Wang *
9743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  @todo We would like to be able to check for noninterference of
98951a39d68df598db08dfced8b4707755864a0492Ying Wang *  _Position and the range [_First, _Last), but that can't (in
99951a39d68df598db08dfced8b4707755864a0492Ying Wang *  general) be done.
100951a39d68df598db08dfced8b4707755864a0492Ying Wang*/
101951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_insert_range(_Position,_First,_Last)		\
102951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First,_Last);				\
10343f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh__glibcxx_check_insert(_Position)
10443f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh
10543f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh/** Verify that we can insert the values in the iterator range
10643f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  [_First, _Last) into *this after the iterator _Position.  Insertion
10743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  into a container after a specific position requires that the iterator
10843f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  be nonsingular (i.e., either dereferenceable or past-the-end),
10943f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  that it reference the sequence we are inserting into, and that the
11043f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  iterator range [_First, Last) is a valid (possibly empty)
11143f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  range. Note that this macro is only valid when the container is a
11243f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  _Safe_sequence and the iterator is a _Safe_iterator.
11343f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *
11443f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  @todo We would like to be able to check for noninterference of
11543f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  _Position and the range [_First, _Last), but that can't (in
11643f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  general) be done.
11743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh*/
11843f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh#define __glibcxx_check_insert_range_after(_Position,_First,_Last)	\
11943f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
12043f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh__glibcxx_check_insert_after(_Position)
121951a39d68df598db08dfced8b4707755864a0492Ying Wang
122951a39d68df598db08dfced8b4707755864a0492Ying Wang/** Verify that we can erase the element referenced by the iterator
123951a39d68df598db08dfced8b4707755864a0492Ying Wang * _Position. We can erase the element if the _Position iterator is
124951a39d68df598db08dfced8b4707755864a0492Ying Wang * dereferenceable and references this sequence.
125951a39d68df598db08dfced8b4707755864a0492Ying Wang*/
126951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_erase(_Position)				\
127951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(),			\
128951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_erase_bad)	        \
129951a39d68df598db08dfced8b4707755864a0492Ying Wang                      ._M_sequence(*this, "this")			\
130951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Position, #_Position));		\
131951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),			\
132951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_erase_different)    \
133951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_sequence(*this, "this")			\
134951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Position, #_Position))
135951a39d68df598db08dfced8b4707755864a0492Ying Wang
13643f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh/** Verify that we can erase the element after the iterator
13743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh * _Position. We can erase the element if the _Position iterator is
13843f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh * before a dereferenceable one and references this sequence.
13943f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh*/
14043f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh#define __glibcxx_check_erase_after(_Position)				\
14143f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh_GLIBCXX_DEBUG_VERIFY(_Position._M_before_dereferenceable(),		\
14243f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      _M_message(__gnu_debug::__msg_erase_after_bad)	\
14343f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_sequence(*this, "this")			\
14443f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_Position, #_Position));		\
14543f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),			\
14643f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      _M_message(__gnu_debug::__msg_erase_different)	\
14743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_sequence(*this, "this")			\
14843f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_Position, #_Position))
14943f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh
150951a39d68df598db08dfced8b4707755864a0492Ying Wang/** Verify that we can erase the elements in the iterator range
151951a39d68df598db08dfced8b4707755864a0492Ying Wang *  [_First, _Last). We can erase the elements if [_First, _Last) is a
152951a39d68df598db08dfced8b4707755864a0492Ying Wang *  valid iterator range within this sequence.
153951a39d68df598db08dfced8b4707755864a0492Ying Wang*/
154951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_erase_range(_First,_Last)			\
155951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First,_Last);				\
156951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),			\
157951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_erase_different)    \
158951a39d68df598db08dfced8b4707755864a0492Ying Wang                      ._M_sequence(*this, "this")			\
159951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_First, #_First)			\
160951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last))
161951a39d68df598db08dfced8b4707755864a0492Ying Wang
16243f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh/** Verify that we can erase the elements in the iterator range
16343f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  (_First, _Last). We can erase the elements if (_First, _Last) is a
16443f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh *  valid iterator range within this sequence.
16543f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh*/
16643f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh#define __glibcxx_check_erase_range_after(_First,_Last)			\
16743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First._M_can_compare(_Last),			\
16843f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      _M_message(__gnu_debug::__msg_erase_different)	\
16943f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_sequence(*this, "this")			\
17043f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_First, #_First)			\
17143f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_Last, #_Last));			\
17243f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),			\
17343f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      _M_message(__gnu_debug::__msg_erase_different)	\
17443f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_sequence(*this, "this")			\
17543f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_First, #_First));			\
17643f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First != _Last,					\
17743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      _M_message(__gnu_debug::__msg_valid_range2)	\
17843f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_sequence(*this, "this")			\
17943f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_First, #_First)			\
18043f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_Last, #_Last));			\
18143f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First._M_incrementable(),			\
18243f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      _M_message(__gnu_debug::__msg_valid_range2)	\
18343f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_sequence(*this, "this")			\
18443f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_First, #_First)			\
18543f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_Last, #_Last));			\
18643f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh_GLIBCXX_DEBUG_VERIFY(!_Last._M_is_before_begin(),			\
18743f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      _M_message(__gnu_debug::__msg_valid_range2)	\
18843f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_sequence(*this, "this")			\
18943f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_First, #_First)			\
19043f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh		      ._M_iterator(_Last, #_Last))			\
19143f272afd56a57640c62c952f9266478bacf0244Andrew Hsieh
192951a39d68df598db08dfced8b4707755864a0492Ying Wang// Verify that the subscript _N is less than the container's size.
193951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_subscript(_N)					\
194951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(_N < this->size(),				\
195951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_subscript_oob)      \
196951a39d68df598db08dfced8b4707755864a0492Ying Wang                      ._M_sequence(*this, "this")			\
197951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_integer(_N, #_N)				\
198951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_integer(this->size(), "size"))
199951a39d68df598db08dfced8b4707755864a0492Ying Wang
200951a39d68df598db08dfced8b4707755864a0492Ying Wang// Verify that the container is nonempty
201951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_nonempty()					\
202951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(! this->empty(),					\
203951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_empty)	        \
204951a39d68df598db08dfced8b4707755864a0492Ying Wang                      ._M_sequence(*this, "this"))
205951a39d68df598db08dfced8b4707755864a0492Ying Wang
206951a39d68df598db08dfced8b4707755864a0492Ying Wang// Verify that the iterator range [_First, _Last) is sorted
207951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_sorted(_First,_Last)				\
208951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First,_Last);				\
209951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last),	\
210951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_unsorted)	        \
211951a39d68df598db08dfced8b4707755864a0492Ying Wang                      ._M_iterator(_First, #_First)			\
212951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last))
213951a39d68df598db08dfced8b4707755864a0492Ying Wang
214951a39d68df598db08dfced8b4707755864a0492Ying Wang/** Verify that the iterator range [_First, _Last) is sorted by the
215951a39d68df598db08dfced8b4707755864a0492Ying Wang    predicate _Pred. */
216951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_sorted_pred(_First,_Last,_Pred)			\
217951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First,_Last);				\
218951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last, _Pred), \
219951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_unsorted_pred)      \
220951a39d68df598db08dfced8b4707755864a0492Ying Wang                      ._M_iterator(_First, #_First)			\
221951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last)			\
222951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_string(#_Pred))
223951a39d68df598db08dfced8b4707755864a0492Ying Wang
224951a39d68df598db08dfced8b4707755864a0492Ying Wang// Special variant for std::merge, std::includes, std::set_*
225951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_sorted_set(_First1,_Last1,_First2)		\
226951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First1,_Last1);				\
227951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(                                                  \
228951a39d68df598db08dfced8b4707755864a0492Ying Wang  __gnu_debug::__check_sorted_set(_First1, _Last1, _First2),		\
229951a39d68df598db08dfced8b4707755864a0492Ying Wang  _M_message(__gnu_debug::__msg_unsorted)				\
230951a39d68df598db08dfced8b4707755864a0492Ying Wang  ._M_iterator(_First1, #_First1)					\
231951a39d68df598db08dfced8b4707755864a0492Ying Wang  ._M_iterator(_Last1, #_Last1))
232951a39d68df598db08dfced8b4707755864a0492Ying Wang
233951a39d68df598db08dfced8b4707755864a0492Ying Wang// Likewise with a _Pred.
234951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred)	\
235951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First1,_Last1);        			\
236951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(							\
237951a39d68df598db08dfced8b4707755864a0492Ying Wang  __gnu_debug::__check_sorted_set(_First1, _Last1, _First2, _Pred),	\
238951a39d68df598db08dfced8b4707755864a0492Ying Wang  _M_message(__gnu_debug::__msg_unsorted_pred)				\
239951a39d68df598db08dfced8b4707755864a0492Ying Wang  ._M_iterator(_First1, #_First1)					\
240951a39d68df598db08dfced8b4707755864a0492Ying Wang  ._M_iterator(_Last1, #_Last1)						\
241951a39d68df598db08dfced8b4707755864a0492Ying Wang  ._M_string(#_Pred))
242951a39d68df598db08dfced8b4707755864a0492Ying Wang
243951a39d68df598db08dfced8b4707755864a0492Ying Wang/** Verify that the iterator range [_First, _Last) is partitioned
244951a39d68df598db08dfced8b4707755864a0492Ying Wang    w.r.t. the value _Value. */
245951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_partitioned_lower(_First,_Last,_Value)		\
246951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First,_Last);				\
247951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
248951a39d68df598db08dfced8b4707755864a0492Ying Wang							    _Value),	\
249951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_unpartitioned)      \
250951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_First, #_First)			\
251951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last)			\
252951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_string(#_Value))
253951a39d68df598db08dfced8b4707755864a0492Ying Wang
254951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_partitioned_upper(_First,_Last,_Value)		\
255951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First,_Last);				\
256951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
257951a39d68df598db08dfced8b4707755864a0492Ying Wang							    _Value),	\
258951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_unpartitioned)      \
259951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_First, #_First)			\
260951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last)			\
261951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_string(#_Value))
262951a39d68df598db08dfced8b4707755864a0492Ying Wang
263951a39d68df598db08dfced8b4707755864a0492Ying Wang/** Verify that the iterator range [_First, _Last) is partitioned
264951a39d68df598db08dfced8b4707755864a0492Ying Wang    w.r.t. the value _Value and predicate _Pred. */
265951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \
266951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First,_Last);				\
267951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
268951a39d68df598db08dfced8b4707755864a0492Ying Wang							 _Value, _Pred), \
269951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_unpartitioned_pred) \
270951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_First, #_First)			\
271951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last)			\
272951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_string(#_Pred)				\
273951a39d68df598db08dfced8b4707755864a0492Ying Wang                      ._M_string(#_Value))
274951a39d68df598db08dfced8b4707755864a0492Ying Wang
275951a39d68df598db08dfced8b4707755864a0492Ying Wang/** Verify that the iterator range [_First, _Last) is partitioned
276951a39d68df598db08dfced8b4707755864a0492Ying Wang    w.r.t. the value _Value and predicate _Pred. */
277951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
278951a39d68df598db08dfced8b4707755864a0492Ying Wang__glibcxx_check_valid_range(_First,_Last);				\
279951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
280951a39d68df598db08dfced8b4707755864a0492Ying Wang							 _Value, _Pred), \
281951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_unpartitioned_pred) \
282951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_First, #_First)			\
283951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last)			\
284951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_string(#_Pred)				\
285951a39d68df598db08dfced8b4707755864a0492Ying Wang                      ._M_string(#_Value))
286951a39d68df598db08dfced8b4707755864a0492Ying Wang
287951a39d68df598db08dfced8b4707755864a0492Ying Wang// Verify that the iterator range [_First, _Last) is a heap
288951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_heap(_First,_Last)				\
289951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last),		        \
290951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_not_heap)	        \
291951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_First, #_First)			\
292951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last))
293951a39d68df598db08dfced8b4707755864a0492Ying Wang
294951a39d68df598db08dfced8b4707755864a0492Ying Wang/** Verify that the iterator range [_First, _Last) is a heap
295951a39d68df598db08dfced8b4707755864a0492Ying Wang    w.r.t. the predicate _Pred. */
296951a39d68df598db08dfced8b4707755864a0492Ying Wang#define __glibcxx_check_heap_pred(_First,_Last,_Pred)			\
297951a39d68df598db08dfced8b4707755864a0492Ying Wang_GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last, _Pred),		\
298951a39d68df598db08dfced8b4707755864a0492Ying Wang		      _M_message(__gnu_debug::__msg_not_heap_pred)      \
299951a39d68df598db08dfced8b4707755864a0492Ying Wang                      ._M_iterator(_First, #_First)			\
300951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_iterator(_Last, #_Last)			\
301951a39d68df598db08dfced8b4707755864a0492Ying Wang		      ._M_string(#_Pred))
302951a39d68df598db08dfced8b4707755864a0492Ying Wang
303951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifdef _GLIBCXX_DEBUG_PEDANTIC
304951a39d68df598db08dfced8b4707755864a0492Ying Wang#  define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0)
305951a39d68df598db08dfced8b4707755864a0492Ying Wang#  define __glibcxx_check_string_len(_String,_Len) \
306951a39d68df598db08dfced8b4707755864a0492Ying Wang       _GLIBCXX_DEBUG_ASSERT(_String != 0 || _Len == 0)
307951a39d68df598db08dfced8b4707755864a0492Ying Wang#else
308951a39d68df598db08dfced8b4707755864a0492Ying Wang#  define __glibcxx_check_string(_String)
309951a39d68df598db08dfced8b4707755864a0492Ying Wang#  define __glibcxx_check_string_len(_String,_Len)
310951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif
311951a39d68df598db08dfced8b4707755864a0492Ying Wang
312951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif
313