mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 23:25:24 +02:00
libstdc++: Fix concept checks for std::unique_copy [PR120384]
This looks to have been wrong since r0-125454-gea89b2482f97aa which introduced the predefined_ops.h. Since that change, the binary predicate passed to std::__unique_copy is _Iter_comp_iter, which takes arguments of the iterator type, not the iterator's value type. This removes the checks from the __unique_copy overloads and moves them into the second overload of std::unique_copy, where we have the original binary predicate, not the adapted one from predefined_ops.h. The third __unique_copy overload currently checks that the predicate is callable with the input range value type and the output range value type. This change alters that, so that we only ever check that the predicate can be called with two arguments of the same type. That is intentional, because calling the predicate with different types is a bug that will be fixed in a later commit (see PR libstdc++/120386). libstdc++-v3/ChangeLog: PR libstdc++/120384 * include/bits/stl_algo.h (__unique_copy): Remove all _BinaryPredicateConcept concept checks. (unique_copy): Check _BinaryPredicateConcept in overload that takes a predicate. * testsuite/25_algorithms/unique_copy/120384.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
This commit is contained in:
committed by
Jonathan Wakely
parent
b2aeeb2803
commit
1bb7a195e7
@@ -932,11 +932,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
_OutputIterator __result, _BinaryPredicate __binary_pred,
|
||||
forward_iterator_tag, output_iterator_tag)
|
||||
{
|
||||
// concept requirements -- iterators already checked
|
||||
__glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
|
||||
typename iterator_traits<_ForwardIterator>::value_type,
|
||||
typename iterator_traits<_ForwardIterator>::value_type>)
|
||||
|
||||
_ForwardIterator __next = __first;
|
||||
*__result = *__first;
|
||||
while (++__next != __last)
|
||||
@@ -962,11 +957,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
_OutputIterator __result, _BinaryPredicate __binary_pred,
|
||||
input_iterator_tag, output_iterator_tag)
|
||||
{
|
||||
// concept requirements -- iterators already checked
|
||||
__glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
|
||||
typename iterator_traits<_InputIterator>::value_type,
|
||||
typename iterator_traits<_InputIterator>::value_type>)
|
||||
|
||||
typename iterator_traits<_InputIterator>::value_type __value = *__first;
|
||||
__decltype(__gnu_cxx::__ops::__iter_comp_val(__binary_pred))
|
||||
__rebound_pred
|
||||
@@ -995,10 +985,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
_ForwardIterator __result, _BinaryPredicate __binary_pred,
|
||||
input_iterator_tag, forward_iterator_tag)
|
||||
{
|
||||
// concept requirements -- iterators already checked
|
||||
__glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
|
||||
typename iterator_traits<_ForwardIterator>::value_type,
|
||||
typename iterator_traits<_InputIterator>::value_type>)
|
||||
*__result = *__first;
|
||||
while (++__first != __last)
|
||||
if (!__binary_pred(__result, __first))
|
||||
@@ -4505,6 +4491,9 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
|
||||
__glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
|
||||
typename iterator_traits<_InputIterator>::value_type>)
|
||||
__glibcxx_requires_valid_range(__first, __last);
|
||||
__glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
|
||||
typename iterator_traits<_InputIterator>::value_type,
|
||||
typename iterator_traits<_InputIterator>::value_type>)
|
||||
|
||||
if (__first == __last)
|
||||
return __result;
|
||||
|
||||
12
libstdc++-v3/testsuite/25_algorithms/unique_copy/120384.cc
Normal file
12
libstdc++-v3/testsuite/25_algorithms/unique_copy/120384.cc
Normal file
@@ -0,0 +1,12 @@
|
||||
// { dg-options "-D_GLIBCXX_CONCEPT_CHECKS" }
|
||||
// { dg-do compile }
|
||||
|
||||
// PR 120384 _BinaryPredicateConcept checks in std::unique_copy are wrong
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
void
|
||||
test_pr120384(const int* first, const int* last, int* out)
|
||||
{
|
||||
std::unique_copy(first, last, out);
|
||||
}
|
||||
Reference in New Issue
Block a user