[libcxx-commits] [libcxx] d9c2256 - [libc++][test] Fix `overload_compare_iterator::iterator_category` (#112165)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 15 07:35:19 PDT 2024
Author: A. Jiang
Date: 2024-10-15T22:35:16+08:00
New Revision: d9c2256c97948b648cb17a3757660070be5987a6
URL: https://github.com/llvm/llvm-project/commit/d9c2256c97948b648cb17a3757660070be5987a6
DIFF: https://github.com/llvm/llvm-project/commit/d9c2256c97948b648cb17a3757660070be5987a6.diff
LOG: [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.
Added:
Modified:
libcxx/test/std/utilities/memory/specialized.algorithms/overload_compare_iterator.h
Removed:
################################################################################
diff --git a/libcxx/test/std/utilities/memory/specialized.algorithms/overload_compare_iterator.h b/libcxx/test/std/utilities/memory/specialized.algorithms/overload_compare_iterator.h
index d5dcb08c37ed6f..f3b37292e717a1 100644
--- a/libcxx/test/std/utilities/memory/specialized.algorithms/overload_compare_iterator.h
+++ b/libcxx/test/std/utilities/memory/specialized.algorithms/overload_compare_iterator.h
@@ -12,6 +12,7 @@
#include <iterator>
#include <memory>
+#include <type_traits>
#include "test_macros.h"
@@ -21,11 +22,15 @@
// See https://github.com/llvm/llvm-project/issues/69334 for details.
template <class Iterator>
struct overload_compare_iterator {
+ static_assert(
+ std::is_base_of<std::forward_iterator_tag, typename std::iterator_traits<Iterator>::iterator_category>::value,
+ "overload_compare_iterator can only adapt forward iterators");
+
using value_type = typename std::iterator_traits<Iterator>::value_type;
using
diff erence_type = typename std::iterator_traits<Iterator>::
diff erence_type;
using reference = typename std::iterator_traits<Iterator>::reference;
using pointer = typename std::iterator_traits<Iterator>::pointer;
- using iterator_category = typename std::iterator_traits<Iterator>::iterator_category;
+ using iterator_category = std::forward_iterator_tag;
overload_compare_iterator() = default;
More information about the libcxx-commits
mailing list