137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Debugging support implementation -*- C++ -*-
237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Free Software Foundation, Inc.
537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh//
637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// This file is part of the GNU ISO C++ Library.  This library is free
737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// software; you can redistribute it and/or modify it under the
837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// terms of the GNU General Public License as published by the
937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Free Software Foundation; either version 3, or (at your option)
1037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// any later version.
1137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
1237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// This library is distributed in the hope that it will be useful,
1337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// but WITHOUT ANY WARRANTY; without even the implied warranty of
1437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// GNU General Public License for more details.
1637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
1737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Under Section 7 of GPL version 3, you are granted additional
1837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// permissions described in the GCC Runtime Library Exception, version
1937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// 3.1, as published by the Free Software Foundation.
2037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
2137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// You should have received a copy of the GNU General Public License and
2237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// a copy of the GCC Runtime Library Exception along with this program;
2337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// <http://www.gnu.org/licenses/>.
2537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
2637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** @file debug/macros.h
2737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  This file is a GNU debug extension to the Standard C++ Library.
2837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh */
2937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
3037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#ifndef _GLIBCXX_DEBUG_MACROS_H
3137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define _GLIBCXX_DEBUG_MACROS_H 1
3237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
3337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/**
3437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * Macros used by the implementation to verify certain
3537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * properties. These macros may only be used directly by the debug
3637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * wrappers. Note that these are macros (instead of the more obviously
3737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * @a correct choice of making them functions) because we need line and
3837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * file information at the call site, to minimize the distance between
3937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * the user error and where the error is reported.
4037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *
4137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh */
4237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define _GLIBCXX_DEBUG_VERIFY_AT(_Condition,_ErrorMessage,_File,_Line)	\
4337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  do									\
4437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  {									\
4537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh    if (! (_Condition))							\
4637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh      __gnu_debug::_Error_formatter::_M_at(_File, _Line)		\
4737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh	  ._ErrorMessage._M_error();					\
4837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  } while (false)
4937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
5037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage)			\
5137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  _GLIBCXX_DEBUG_VERIFY_AT(_Condition,_ErrorMessage,__FILE__,__LINE__)
5237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
5337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Verify that [_First, _Last) forms a valid iterator range.
5437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_valid_range(_First,_Last)			\
5537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last),	\
5637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_valid_range)	\
5737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
5837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last))
5937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
6037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Verify that [_First, _Last) forms a non-empty iterator range.
6137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_non_empty_range(_First,_Last)			\
6237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First != _Last,					\
6337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_non_empty_range)	\
6437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
6537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last))
6637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
6737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that we can insert into *this with the iterator _Position.
6837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  Insertion into a container at a specific position requires that
6937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  the iterator be nonsingular, either dereferenceable or past-the-end,
7037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  and that it reference the sequence we are inserting into. Note that
7137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  this macro is only valid when the container is a_Safe_sequence and
7237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  the iterator is a _Safe_iterator.
7337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh*/
7437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_insert(_Position)				\
7537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),				\
7637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_insert_singular) \
7737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
7837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Position, #_Position));		\
7937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),			\
8037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_insert_different) \
8137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
8237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Position, #_Position))
8337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
8437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that we can insert into *this after the iterator _Position.
8537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  Insertion into a container after a specific position requires that
8637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  the iterator be nonsingular, either dereferenceable or before-begin,
8737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  and that it reference the sequence we are inserting into. Note that
8837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  this macro is only valid when the container is a_Safe_sequence and
8937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  the iterator is a _Safe_iterator.
9037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh*/
9137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_insert_after(_Position)				\
9237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_insert(_Position);					\
9337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(!_Position._M_is_end(),				\
9437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_insert_after_end)	\
9537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
9637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Position, #_Position))
9737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
9837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that we can insert the values in the iterator range
9937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  [_First, _Last) into *this with the iterator _Position.  Insertion
10037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  into a container at a specific position requires that the iterator
10137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  be nonsingular (i.e., either dereferenceable or past-the-end),
10237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  that it reference the sequence we are inserting into, and that the
10337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  iterator range [_First, Last) is a valid (possibly empty)
10437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  range. Note that this macro is only valid when the container is a
10537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  _Safe_sequence and the iterator is a _Safe_iterator.
10637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *
10737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  @todo We would like to be able to check for noninterference of
10837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  _Position and the range [_First, _Last), but that can't (in
10937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  general) be done.
11037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh*/
11137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_insert_range(_Position,_First,_Last)		\
11237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
11337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_insert(_Position)
11437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
11537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that we can insert the values in the iterator range
11637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  [_First, _Last) into *this after the iterator _Position.  Insertion
11737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  into a container after a specific position requires that the iterator
11837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  be nonsingular (i.e., either dereferenceable or past-the-end),
11937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  that it reference the sequence we are inserting into, and that the
12037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  iterator range [_First, Last) is a valid (possibly empty)
12137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  range. Note that this macro is only valid when the container is a
12237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  _Safe_sequence and the iterator is a _Safe_iterator.
12337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *
12437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  @todo We would like to be able to check for noninterference of
12537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  _Position and the range [_First, _Last), but that can't (in
12637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  general) be done.
12737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh*/
12837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_insert_range_after(_Position,_First,_Last)	\
12937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
13037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_insert_after(_Position)
13137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
13237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that we can erase the element referenced by the iterator
13337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * _Position. We can erase the element if the _Position iterator is
13437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * dereferenceable and references this sequence.
13537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh*/
13637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_erase(_Position)				\
13737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(),			\
13837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_erase_bad)	        \
13937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh                      ._M_sequence(*this, "this")			\
14037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Position, #_Position));		\
14137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),			\
14237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_erase_different)    \
14337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
14437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Position, #_Position))
14537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
14637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that we can erase the element after the iterator
14737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * _Position. We can erase the element if the _Position iterator is
14837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh * before a dereferenceable one and references this sequence.
14937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh*/
15037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_erase_after(_Position)				\
15137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_Position._M_before_dereferenceable(),		\
15237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_erase_after_bad)	\
15337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
15437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Position, #_Position));		\
15537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),			\
15637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_erase_different)	\
15737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
15837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Position, #_Position))
15937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
16037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that we can erase the elements in the iterator range
16137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  [_First, _Last). We can erase the elements if [_First, _Last) is a
16237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  valid iterator range within this sequence.
16337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh*/
16437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_erase_range(_First,_Last)			\
16537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
16637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),			\
16737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_erase_different)    \
16837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh                      ._M_sequence(*this, "this")			\
16937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
17037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last))
17137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
17237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that we can erase the elements in the iterator range
17337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  (_First, _Last). We can erase the elements if (_First, _Last) is a
17437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh *  valid iterator range within this sequence.
17537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh*/
17637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_erase_range_after(_First,_Last)			\
17737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First._M_can_compare(_Last),			\
17837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_erase_different)	\
17937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
18037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
18137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last));			\
18237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),			\
18337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_erase_different)	\
18437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
18537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First));			\
18637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First != _Last,					\
18737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_valid_range2)	\
18837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
18937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
19037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last));			\
19137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_First._M_incrementable(),			\
19237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_valid_range2)	\
19337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
19437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
19537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last));			\
19637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(!_Last._M_is_before_begin(),			\
19737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_valid_range2)	\
19837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_sequence(*this, "this")			\
19937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
20037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last))			\
20137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
20237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Verify that the subscript _N is less than the container's size.
20337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_subscript(_N)					\
20437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(_N < this->size(),				\
20537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_subscript_oob)      \
20637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh                      ._M_sequence(*this, "this")			\
20737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_integer(_N, #_N)				\
20837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_integer(this->size(), "size"))
20937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
21037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Verify that the container is nonempty
21137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_nonempty()					\
21237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(! this->empty(),					\
21337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_empty)	        \
21437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh                      ._M_sequence(*this, "this"))
21537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
21637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Verify that the iterator range [_First, _Last) is sorted
21737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_sorted(_First,_Last)				\
21837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
21937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last),	\
22037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_unsorted)	        \
22137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh                      ._M_iterator(_First, #_First)			\
22237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last))
22337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
22437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that the iterator range [_First, _Last) is sorted by the
22537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh    predicate _Pred. */
22637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_sorted_pred(_First,_Last,_Pred)			\
22737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
22837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last, _Pred), \
22937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_unsorted_pred)      \
23037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh                      ._M_iterator(_First, #_First)			\
23137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last)			\
23237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_string(#_Pred))
23337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
23437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Special variant for std::merge, std::includes, std::set_*
23537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_sorted_set(_First1,_Last1,_First2)		\
23637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First1,_Last1);				\
23737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(                                                  \
23837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  __gnu_debug::__check_sorted_set(_First1, _Last1, _First2),		\
23937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  _M_message(__gnu_debug::__msg_unsorted)				\
24037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  ._M_iterator(_First1, #_First1)					\
24137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  ._M_iterator(_Last1, #_Last1))
24237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
24337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Likewise with a _Pred.
24437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred)	\
24537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First1,_Last1);        			\
24637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(							\
24737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  __gnu_debug::__check_sorted_set(_First1, _Last1, _First2, _Pred),	\
24837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  _M_message(__gnu_debug::__msg_unsorted_pred)				\
24937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  ._M_iterator(_First1, #_First1)					\
25037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  ._M_iterator(_Last1, #_Last1)						\
25137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh  ._M_string(#_Pred))
25237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
25337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that the iterator range [_First, _Last) is partitioned
25437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh    w.r.t. the value _Value. */
25537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_partitioned_lower(_First,_Last,_Value)		\
25637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
25737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
25837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh							    _Value),	\
25937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_unpartitioned)      \
26037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
26137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last)			\
26237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_string(#_Value))
26337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
26437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_partitioned_upper(_First,_Last,_Value)		\
26537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
26637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
26737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh							    _Value),	\
26837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_unpartitioned)      \
26937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
27037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last)			\
27137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_string(#_Value))
27237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
27337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that the iterator range [_First, _Last) is partitioned
27437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh    w.r.t. the value _Value and predicate _Pred. */
27537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \
27637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
27737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
27837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh							 _Value, _Pred), \
27937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_unpartitioned_pred) \
28037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
28137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last)			\
28237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_string(#_Pred)				\
28337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh                      ._M_string(#_Value))
28437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
28537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that the iterator range [_First, _Last) is partitioned
28637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh    w.r.t. the value _Value and predicate _Pred. */
28737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
28837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh__glibcxx_check_valid_range(_First,_Last);				\
28937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
29037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh							 _Value, _Pred), \
29137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_unpartitioned_pred) \
29237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
29337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last)			\
29437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_string(#_Pred)				\
29537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh                      ._M_string(#_Value))
29637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
29737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh// Verify that the iterator range [_First, _Last) is a heap
29837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_heap(_First,_Last)				\
29937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last),		        \
30037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_not_heap)	        \
30137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_First, #_First)			\
30237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last))
30337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
30437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh/** Verify that the iterator range [_First, _Last) is a heap
30537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh    w.r.t. the predicate _Pred. */
30637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#define __glibcxx_check_heap_pred(_First,_Last,_Pred)			\
30737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh_GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last, _Pred),		\
30837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      _M_message(__gnu_debug::__msg_not_heap_pred)      \
30937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh                      ._M_iterator(_First, #_First)			\
31037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_iterator(_Last, #_Last)			\
31137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh		      ._M_string(#_Pred))
31237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
31337f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#ifdef _GLIBCXX_DEBUG_PEDANTIC
31437f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#  define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0)
31537f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#  define __glibcxx_check_string_len(_String,_Len) \
31637f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh       _GLIBCXX_DEBUG_ASSERT(_String != 0 || _Len == 0)
31737f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#else
31837f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#  define __glibcxx_check_string(_String)
31937f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#  define __glibcxx_check_string_len(_String,_Len)
32037f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#endif
32137f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh
32237f12739251d2637c9405c75951962b5e27bbceeAndrew Hsieh#endif
323