gcc/libstdc++-v3/testsuite/25_algorithms
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
..
adjacent_find libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
advance/istreambuf_iterators Update copyright years. 2020-01-01 12:51:42 +01:00
all_of libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
any_of libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
binary_search libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
clamp libstdc++: P1243R4 Rangify new algorithms 2020-02-18 11:06:49 -05:00
copy libstdc++: Fix some ranges algos optimizations [PR95578] 2020-06-10 17:37:53 -04:00
copy_backward libstdc++: Fix some ranges algos optimizations [PR95578] 2020-06-10 17:37:53 -04:00
copy_if libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
copy_n libstdc++: Specialize copy/copy_n for istreambuf_iterator and deque iterators 2020-06-04 22:27:47 +02:00
count libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
count_if libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
equal libstdc++: Fix some ranges algos optimizations [PR95578] 2020-06-10 17:37:53 -04:00
equal_range libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
fill libstdc++ std::fill overload for std::vector<bool>::iterator 2020-05-06 23:28:22 +02:00
fill_n libstdc++: Make byte-sized std::fill_n a constant expression (PR 94933) 2020-05-03 13:33:15 +01:00
find libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
find_end libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
find_first_of libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
find_if libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
find_if_not libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
for_each libstdc++: P1243R4 Rangify new algorithms 2020-02-18 11:06:49 -05:00
generate libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
generate_n libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
headers Update copyright years. 2020-01-01 12:51:42 +01:00
heap libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
includes libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
inplace_merge libstdc++: -D_GLIBCXX_DEBUG fixes in the constrained algos tests 2020-02-27 12:47:17 -05:00
is_heap Update copyright years. 2020-01-01 12:51:42 +01:00
is_heap_until Update copyright years. 2020-01-01 12:51:42 +01:00
is_partitioned libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
is_permutation libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
is_sorted libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
is_sorted_until libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
iter_swap Update copyright years. 2020-01-01 12:51:42 +01:00
lexicographical_compare libstdc++: Fix some ranges algos optimizations [PR95578] 2020-06-10 17:37:53 -04:00
lexicographical_compare_three_way Update copyright years. 2020-01-01 12:51:42 +01:00
lower_bound libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
make_heap Update copyright years. 2020-01-01 12:51:42 +01:00
max libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
max_element libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
merge libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
min libstdc++: Make _GLIBCXX_CONCEPT_CHECKS more constexpr-friendly 2020-02-27 10:52:28 +00:00
min_element libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
minmax libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
minmax_element libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
mismatch libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
move libstdc++: Fix some ranges algos optimizations [PR95578] 2020-06-10 17:37:53 -04:00
move_backward libstdc++: Fix some ranges algos optimizations [PR95578] 2020-06-10 17:37:53 -04:00
next_permutation libstdc++: P2106R0 Alternative wording for GB315 and GB316 2020-02-18 11:06:50 -05:00
none_of libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
nth_element libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
partial_sort libstdc++: -D_GLIBCXX_DEBUG fixes in the constrained algos tests 2020-02-27 12:47:17 -05:00
partial_sort_copy libstdc++: -D_GLIBCXX_DEBUG fixes in the constrained algos tests 2020-02-27 12:47:17 -05:00
partition libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
partition_copy libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
partition_point libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
pop_heap Update copyright years. 2020-01-01 12:51:42 +01:00
prev_permutation libstdc++: P2106R0 Alternative wording for GB315 and GB316 2020-02-18 11:06:50 -05:00
pstl libstdc++: Define __cpp_lib_execution feature test macro 2020-04-22 22:54:35 +01:00
push_heap Update copyright years. 2020-01-01 12:51:42 +01:00
random_shuffle Update copyright years. 2020-01-01 12:51:42 +01:00
remove libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
remove_copy libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
remove_copy_if libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
remove_if libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
replace libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
replace_copy libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
replace_copy_if libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
replace_if libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
reverse libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
reverse_copy libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
rotate libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
rotate_copy libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
sample libstdc++: P1243R4 Rangify new algorithms 2020-02-18 11:06:49 -05:00
search libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
search_n libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
set_difference libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
set_intersection libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
set_symmetric_difference libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
set_union libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
shift_left libstdc++: P0769R2 Add shift to <algorithm> 2020-02-24 10:08:57 -05:00
shift_right libstdc++: P0769R2 Add shift to <algorithm> 2020-02-24 10:08:57 -05:00
shuffle libstdc++: -D_GLIBCXX_DEBUG fixes in the constrained algos tests 2020-02-27 12:47:17 -05:00
sort libstdc++: -D_GLIBCXX_DEBUG fixes in the constrained algos tests 2020-02-27 12:47:17 -05:00
sort_heap Update copyright years. 2020-01-01 12:51:42 +01:00
stable_partition libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
stable_sort libstdc++: -D_GLIBCXX_DEBUG fixes in the constrained algos tests 2020-02-27 12:47:17 -05:00
swap Update copyright years. 2020-01-01 12:51:42 +01:00
swap_ranges libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
transform libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
unique libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
unique_copy libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
upper_bound libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
constexpr_macro.cc Update copyright years. 2020-01-01 12:51:42 +01:00
cpp_lib_constexpr.cc Update copyright years. 2020-01-01 12:51:42 +01:00