24167c42e6
2015-06-29 François Dumont <fdumont@gcc.gnu.org> * include/bits/stl_iterator_base_types.h (_Iter_base): Limit definition to pre-C++11 mode. * include/debug/functions.h (__gnu_debug::__valid_range, __gnu_debug::__base): Move... * include/debug/safe_iterator.h (__gnu_debug::_Sequence_traits): New. (__gnu_debug::__get_distance_from_begin): New. (__gnu_debug::__get_distance_to_end): New. (__gnu_debug::_Safe_iterator<>::_M_valid_range): Expose iterator range distance information. Add optional check_dereferenceable parameter, default true. (__gnu_debug::_Distance_precision, __gnu_debug::__get_distance): Move default definition... (__gnu_debug::__get_distance): New overload for _Safe_iterator. (__gnu_debug::__unsafe): Likewise. * include/debug/helper_functions.h: ...here. New. (__gnu_debug::__unsafe): New helper function to remove safe iterator layer. * include/debug/stl_iterator.h: New. Include latter. * include/bits/stl_iterator.h: Include latter in debug mode. * include/debug/stl_iterator.tcc: Adapt. * include/debug/safe_local_iterator.h (__gnu_debug::__get_distance): Add overload for _Safe_local_iterator. (__gnu_debug::__unsafe): Likewise. * include/debug/safe_local_iterator.tcc: Adapt. * include/debug/macros.h (__glibcxx_check_valid_range2): New. (__glibcxx_check_insert_range): Add _Dist parameter. (__glibcxx_check_insert_range_after): Likewise. (__glibcxx_check_string, __glibcxx_check_string_len): Implement using _GLIBCXX_DEBUG_PEDASSERT. * include/debug/deque (deque<>::assign): Remove iterator debug layer when possible. (deque<>::insert): Likewise. * include/debug/forward_list (__glibcxx_check_valid_fl_range): New. (forward_list<>::splice_after): Use latter. (forward_list<>::assign): Remove iterator debug layer when possible. (forward_list<>::insert_after): Likewise. (__gnu_debug::_Sequence_traits<>): Partial specialization. * include/debug/list (list<>::assign): Remove iterator debug layer when possible. (list<>::insert): Likewise. [__gnu_debug::_Sequence_traits<>]: Partial specialization pre C++11 ABI. * include/debug/map.h (map<>::insert): Remove iterator debug layer when possible. * include/debug/multimap.h (multimap<>::insert): Likewise. * include/debug/set.h (set<>::insert): Likewise. * include/debug/multiset.h (multiset<>::insert): Likewise. * include/debug/string (basic_string<>::append, basic_string<>::assign, basic_string<>::insert, basic_string<>::replace): Likewise. * include/debug/unordered_map (unordered_map<>::insert, unordered_multimap<>::insert): Likewise. * include/debug/unordered_set (unordered_set<>::insert, unordered_multiset<>insert): Likewise. * include/debug/vector (vector<>::assign, vector<>::insert): Likewise. * include/Makefile.am: Add new debug headers. * include/Makefile.in: Regenerate. From-SVN: r225143
97 lines
2.9 KiB
C++
97 lines
2.9 KiB
C++
// Debugging iterator implementation (out of line) -*- C++ -*-
|
|
|
|
// Copyright (C) 2003-2015 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 3, or (at your option)
|
|
// any later version.
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
// 3.1, as published by the Free Software Foundation.
|
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
/** @file debug/safe_iterator.tcc
|
|
* This file is a GNU debug extension to the Standard C++ Library.
|
|
*/
|
|
|
|
#ifndef _GLIBCXX_DEBUG_SAFE_ITERATOR_TCC
|
|
#define _GLIBCXX_DEBUG_SAFE_ITERATOR_TCC 1
|
|
|
|
namespace __gnu_debug
|
|
{
|
|
template<typename _Iterator, typename _Sequence>
|
|
bool
|
|
_Safe_iterator<_Iterator, _Sequence>::
|
|
_M_can_advance(const difference_type& __n) const
|
|
{
|
|
if (this->_M_singular())
|
|
return false;
|
|
|
|
if (__n == 0)
|
|
return true;
|
|
|
|
if (__n < 0)
|
|
{
|
|
std::pair<difference_type, _Distance_precision> __dist =
|
|
__get_distance_from_begin(*this);
|
|
bool __ok = ((__dist.second == __dp_exact && __dist.first >= -__n)
|
|
|| (__dist.second != __dp_exact && __dist.first > 0));
|
|
return __ok;
|
|
}
|
|
else
|
|
{
|
|
std::pair<difference_type, _Distance_precision> __dist =
|
|
__get_distance_to_end(*this);
|
|
bool __ok = ((__dist.second == __dp_exact && __dist.first >= __n)
|
|
|| (__dist.second != __dp_exact && __dist.first > 0));
|
|
return __ok;
|
|
}
|
|
}
|
|
|
|
template<typename _Iterator, typename _Sequence>
|
|
bool
|
|
_Safe_iterator<_Iterator, _Sequence>::
|
|
_M_valid_range(const _Safe_iterator& __rhs,
|
|
std::pair<difference_type, _Distance_precision>& __dist,
|
|
bool __check_dereferenceable) const
|
|
{
|
|
if (!_M_can_compare(__rhs))
|
|
return false;
|
|
|
|
/* Determine iterators order */
|
|
__dist = __get_distance(*this, __rhs);
|
|
switch (__dist.second)
|
|
{
|
|
case __dp_equality:
|
|
if (__dist.first == 0)
|
|
return true;
|
|
break;
|
|
|
|
case __dp_sign:
|
|
case __dp_exact:
|
|
// If range is not empty first iterator must be dereferenceable.
|
|
if (__dist.first > 0)
|
|
return !__check_dereferenceable || _M_dereferenceable();
|
|
return __dist.first == 0;
|
|
}
|
|
|
|
// Assume that this is a valid range; we can't check anything else.
|
|
return true;
|
|
}
|
|
} // namespace __gnu_debug
|
|
|
|
#endif
|
|
|