PR libstdc++/68222 Hide safe iterator operators

François Dumont frs.dumont@gmail.com
Thu Aug 2 20:16:00 GMT 2018


Hi

     Here is a patch to avoid definition of invalid operators on the 
Debug mode safe iterator type depending on its category.

     Even if it is limited to the Debug mode code I would like to have a 
feedback before committing. Especially on the following points:

- _Safe_tagged_iterator: Is the name ok ?

- Inheritance between the different _Safe_tagged_iterator 
instantiations. I am already working on making the operators friends as 
we discuss in another thread so I might review this design at this moment.

- Are concept checks I added to testsuite_containers.h citerator ok ?

     This patch also does some cleanup on Debug functions. 
__check_dereferenceable was not used (anymore maybe) so I removed it. I 
also prefer to take iterator by value in the fallback implementations 
like it is done in std algos. Only _Safe_tagged_iterator are taken by 
lvalue ref as they are quite expensive to copy (mutex lock).

     I also attach the ChangeLog entry which is quite big.

Tested under Linux x86_64 Debug mode.

François


-------------- next part --------------
A non-text attachment was scrubbed...
Name: safe_iterator.patch
Type: text/x-patch
Size: 76687 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20180802/03e5cdd4/attachment.bin>
-------------- next part --------------
2018-08-03  François Dumont  <fdumont@gcc.gnu.org>

	* include/debug/safe_iterator.h
	(_Safe_tagged_iterator<_It, _Sq, _Cat =
	typename std::iterator_traits<_It>::iterator_category>): New.
	(_Safe_iterator<_It, _Sq>::operator++()): Move...
	(_Safe_tagged_iterator<_It, _Sq, std::forward_iterator_tag>
	::operator++()): ...here.
	(_Safe_iterator<_It, _Sq>::operator++(int)): Move...
	(_Safe_tagged_iterator<_It, _Sq, std::forward_iterator_tag>
	::operator++(int)): ...here.
	(_Safe_iterator<_It, _Sq>::operator--()): Move...
	(_Safe_tagged_iterator<_It, _Sq, std::bidirectional_iterator_tag>
	::operator--()): ...here.
	(_Safe_iterator<_It, _Sq>::operator--(int)): Move...
	(_Safe_tagged_iterator<_It, _Sq, std::bidirectional_iterator_tag>
	::operator--(int)): ...here.
	(_Safe_iterator<_It, _Sq>::operator[](const difference_type&)): Move...
	(_Safe_tagged_iterator<_It, _Sq, std::random_access_iterator_tag>
	::operator[](const difference_type&)): ...here.
	(_Safe_iterator<_It, _Sq>::operator+=(const difference_type&)): Move...
	(_Safe_tagged_iterator<_It, _Sq, std::random_access_iterator_tag>
	::operator+=(const difference_type&)): ...here.
	(_Safe_iterator<_It, _Sq>::operator+(const difference_type&)): Move...
	(_Safe_tagged_iterator<_It, _Sq, std::random_access_iterator_tag>
	::operator+(const difference_type&)): ...here.
	(_Safe_iterator<_It, _Sq>::operator-=(const difference_type&)): Move...
	(_Safe_tagged_iterator<_It, _Sq, std::random_access_iterator_tag>
	::operator-=(const difference_type&)): ...here.
	(_Safe_iterator<_It, _Sq>::operator-(const difference_type&)): Move...
	(_Safe_tagged_iterator<_It, _Sq, std::random_access_iterator_tag>
	::operator-(const difference_type&)): ...here.
	(operator==(const _Safe_iterator<>&, const _Safe_iterator<>&)): Replace
	with...
	(operator==(const _Safe_tagged_iterator<>&,
	const _Safe_tagged_iterator<>&): ...that.
	(operator==(const _Safe_iterator<>&, const _Safe_iterator<>&)): Replace
	with...
	(operator==(const _Safe_tagged_iterator<>&,
	const _Safe_tagged_iterator<>&): ...that.
	(operator!=(const _Safe_iterator<>&, const _Safe_iterator<>&)): Replace
	with...
	(operator!=(const _Safe_tagged_iterator<>&,
	const _Safe_tagged_iterator<>&): ...that.
	(operator<(const _Safe_iterator<>&, const _Safe_iterator<>&)): Replace
	with...
	(operator<(const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&,
		const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&)): ...that.
	(operator<=(const _Safe_iterator<>&, const _Safe_iterator<>&)): Replace
	with...
	(operator<=(const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&,
		const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&)): ...that.
	(operator>(const _Safe_iterator<>&, const _Safe_iterator<>&)): Replace
	with...
	(operator>(const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&,
		const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&)): ...that.
	(operator>=(const _Safe_iterator<>&, const _Safe_iterator<>&)): Replace
	with...
	(operator>=(const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&,
		const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&)): ...that.
	(operator-(const _Safe_iterator<>&, const _Safe_iterator<>&)): Replace
	with...
	(operator-(const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&,
		const _Safe_tagged_iterator<_It, _Sq,
		std::random_access_iterator_tag>&)): ...that.
	(operator+(const difference_type&, const _Safe_iterator<>&)): Replace
	with...
	(operator+(const difference_type&,
		const _Safe_tagged_iterator<_It, _Sq,
	std::random_access_iterator_tag>&)): ...that.
	* include/debug/deque
	(std::__debug::deque<>::normal_type): New typedef.
	(std::__debug::deque<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::deque<>::const_iterator): Likewise.
	* include/debug/forward_list
	(std::__debug::forward_list<>::normal_type): New typedef.
	(std::__debug::forward_list<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::forward_list<>::const_iterator): Likewise.
	* include/debug/list
	(std::__debug::list<>::normal_type): New typedef.
	(std::__debug::list<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::list<>::const_iterator): Likewise.
	* include/debug/map.h
	(std::__debug::map<>::normal_type): New typedef.
	(std::__debug::map<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::map<>::const_iterator): Likewise.
	* include/debug/multimap.h
	(std::__debug::multimap<>::normal_type): New typedef.
	(std::__debug::multimap<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::multimap<>::const_iterator): Likewise.
	* include/debug/set.h
	(std::__debug::set<>::normal_type): New typedef.
	(std::__debug::set<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::set<>::const_iterator): Likewise.
	* include/debug/multiset.h
	(std::__debug::multiset<>::normal_type): New typedef.
	(std::__debug::multiset<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::multiset<>::const_iterator): Likewise.
	* include/debug/string
	(std::__debug::basic_string<>::normal_type): New typedef.
	(std::__debug::basic_string<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::basic_string<>::const_iterator): Likewise.
	* include/debug/unordered_map
	(std::__debug::unordered_map<>::normal_type): New typedef.
	(std::__debug::unordered_map<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::unordered_map<>::const_iterator): Likewise.
	(std::__debug::unordered_multimap<>::normal_type): New typedef.
	(std::__debug::unordered_multimap<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::unordered_multimap<>::const_iterator): Likewise.
	* include/debug/unordered_set
	(std::__debug::unordered_set<>::normal_type): New typedef.
	(std::__debug::unordered_set<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::unordered_set<>::const_iterator): Likewise.
	(std::__debug::unordered_multiset<>::normal_type): New typedef.
	(std::__debug::unordered_multiset<>::iterator): Use _Safe_tagged_iterator.
	(std::__debug::unordered_multiset<>::const_iterator): Likewise.
	* include/debug/formatter.h: Adapt.
	* include/debug/helper_functions.h
	(__get_distance<>(const _Safe_tagged_iterator<>&,
	const _Safe_tagged_iterator<>&)): New definition.
	(__get_distance<>(const _Safe_local_iterator<>&,
	const _Safe_local_iterator<>&)): Likewise.
	(__valid_range(const _Safe_tagged_iterator<>&,
	const _Safe_tagged_iterator<>&, typename _Distance_traits<>::__type&):
	Likewise.
	(__valid_range(const _Safe_local_iterator<>&,
	const _Safe_local_iterator<>&, typename _Distance_traits<>::__type&):
	Likewise.
	(__can_advance): Adapt.
	(__is_safe_random_iterator<>): Remove.
	* include/debug/functions.h: Include <bits/stl_iterator.h>.
	(__check_dereferenceable): Delete.
	(__foreign_iterator_aux4, __foreign_iterator_aux3): Adapt.
	(__foreign_iterator_aux2, __foreign_iterator_aux): Adapt.
	(__foreign_iterator): Adapt.
	* include/debug/stl_iterator.h
	(__is_safe_random_iterator<std::reverse_iterator<>>): Remove.
	(__base(const std::reverse_iterator<_Safe_tagged_iterator<_It, _Sq,
	std::random_access_iterator_tag>)): New overload.
	(__niter_base): Adapt.
	* testsuite/util/testsuite_containers.h:
	Include <bits/boost_concept_check.h>.
	(iterator_concept_checks<_It, _Mutable, _Category>): New.
	(citerator<_Cont>::forward_members::forward_members()): Instantiate
	latter for container iterator and const_iterator.
	* testsuite/23_containers/list/68222_neg.cc: New.
	* testsuite/23_containers/vector/cons/destructible_debug_neg.cc: Adapt
	line number.


More information about the Libstdc++ mailing list