Skip to content

Commit d9c2256

Browse files
[libc++][test] Fix overload_compare_iterator::iterator_category (#112165)
`overload_compare_iterator` only supports operations required for forward iterators. On the other hand, it is used for output iterators of uninitialized memory algorithms, which requires it to be forward iterator. As a result, `overload_compare_iterator<I>::iterator_category` should always be `std::forward_iterator_tag` if we don't extend its ability. The correct `iterator_category` can prevent standard library implementations like MSVC STL attempting random access operations on `overload_compare_iterator`. Fixes #74756.
1 parent c5c27d8 commit d9c2256

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libcxx/test/std/utilities/memory/specialized.algorithms/overload_compare_iterator.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <iterator>
1414
#include <memory>
15+
#include <type_traits>
1516

1617
#include "test_macros.h"
1718

@@ -21,11 +22,15 @@
2122
// See https://github.com/llvm/llvm-project/issues/69334 for details.
2223
template <class Iterator>
2324
struct overload_compare_iterator {
25+
static_assert(
26+
std::is_base_of<std::forward_iterator_tag, typename std::iterator_traits<Iterator>::iterator_category>::value,
27+
"overload_compare_iterator can only adapt forward iterators");
28+
2429
using value_type = typename std::iterator_traits<Iterator>::value_type;
2530
using difference_type = typename std::iterator_traits<Iterator>::difference_type;
2631
using reference = typename std::iterator_traits<Iterator>::reference;
2732
using pointer = typename std::iterator_traits<Iterator>::pointer;
28-
using iterator_category = typename std::iterator_traits<Iterator>::iterator_category;
33+
using iterator_category = std::forward_iterator_tag;
2934

3035
overload_compare_iterator() = default;
3136

0 commit comments

Comments
 (0)