gcc/libstdc++-v3/testsuite/25_algorithms/copy
Patrick Palka a73051a0ea libstdc++: Fix some ranges algos optimizations [PR95578]
ranges::copy and a number of other ranges algorithms have unwrapping
optimizations for iterators of type __normal_iterator, move_iterator and
reverse_iterator.  But in the checks that guard these optimizations we
currently only test that the iterator of the iterator/sentinel pair has
the appropriate type before proceeding with the corresponding
optimization, and do not also test the sentinel type.

This breaks the testcase in this PR because this testcase constructs via
range adaptors a range whose begin() is a __normal_iterator and whose
end() is a custom sentinel type, and then performs ranges::copy on it.
From there we bogusly perform the __normal_iterator unwrapping
optimization on this iterator/sentinel pair, which immediately leads to
a constraint failure since the custom sentinel type does not model
sentinel_for<int*>.

This patch fixes this issue by refining each of the problematic checks
to also test that the iterator and sentinel types are the same before
applying the corresponding unwrapping optimization.  Along the way, some
code simplifications are made.

libstdc++-v3/ChangeLog:

	PR libstdc++/95578
	* include/bits/ranges_algo.h (__lexicographical_compare_fn):
	Also check that the iterator and sentinel have the same type before
	applying the unwrapping optimization for __normal_iterator.
	Split the check into two, one for the first iterator/sentinel
	pair and another for second iterator/sentinel pair.  Remove uses
	of __niter_base, and remove uses of std::move on a
	__normal_iterator.
	* include/bits/ranges_algobase.h (__equal_fn): Likewise.
	(__copy_or_move): Likewise.  Perform similar adjustments for
	the reverse_iterator and move_iterator optimizations.  Inline
	the checks into the if-constexprs, and use using-declarations to
	make them less visually noisy.  Remove uses of __niter_wrap.
	(__copy_or_move_backward): Likewise.
	* testsuite/25_algorithms/copy/95578.cc: New test.
	* testsuite/25_algorithms/copy_backward/95578.cc: New test.
	* testsuite/25_algorithms/equal/95578.cc: New test.
	* testsuite/25_algorithms/lexicographical_compare/95578.cc: New test.
	* testsuite/25_algorithms/move/95578.cc: New test.
	* testsuite/25_algorithms/move_backward/95578.cc: New test.
2020-06-10 17:37:53 -04:00
..
debug libstdc++: Fix function that can't be constexpr in C++11 (PR 95289) 2020-05-23 18:27:35 +01:00
deque_iterators Update copyright years. 2020-01-01 12:51:42 +01:00
move_iterators Update copyright years. 2020-01-01 12:51:42 +01:00
requirements/explicit_instantiation Update copyright years. 2020-01-01 12:51:42 +01:00
streambuf_iterators libstdc++: Specialize copy/copy_n for istreambuf_iterator and deque iterators 2020-06-04 22:27:47 +02:00
1.cc Update copyright years. 2020-01-01 12:51:42 +01:00
2.cc Update copyright years. 2020-01-01 12:51:42 +01:00
3.cc Update copyright years. 2020-01-01 12:51:42 +01:00
4.cc Update copyright years. 2020-01-01 12:51:42 +01:00
34595.cc Update copyright years. 2020-01-01 12:51:42 +01:00
58982.cc Update copyright years. 2020-01-01 12:51:42 +01:00
86658.cc Update copyright years. 2020-01-01 12:51:42 +01:00
94013.cc libstdc++: Workaround is_trivially_copyable<volatile T> (PR 94013) 2020-03-03 21:39:19 +00:00
95578.cc libstdc++: Fix some ranges algos optimizations [PR95578] 2020-06-10 17:37:53 -04:00
constexpr.cc Update copyright years. 2020-01-01 12:51:42 +01:00
constrained.cc libstdc++: -D_GLIBCXX_DEBUG fixes in the constrained algos tests 2020-02-27 12:47:17 -05:00