Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++][test] overload_compare_iterator doesn't support its claimed iterator_category #74756

Closed
StephanTLavavej opened this issue Dec 7, 2023 · 0 comments · Fixed by #112165
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite

Comments

@StephanTLavavej
Copy link
Member

There's an overload_compare_iterator that wraps an Iterator and claims to have the same iterator_category:

// An iterator type that overloads operator== and operator!= without any constraints, which
// can trip up some algorithms if we compare iterators against types that we're not allowed to.
//
// See https://github.com/llvm/llvm-project/issues/69334 for details.
template <class Iterator>
struct overload_compare_iterator {
using value_type = typename std::iterator_traits<Iterator>::value_type;
using difference_type = typename std::iterator_traits<Iterator>::difference_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;

However, it totally doesn't support enough operations. When passed to MSVC's STL, we notice that overload_compare_iterator<int *> claims to be random-access and we try to subtract it, which fails to compile:

In file included from D:\GitHub\STL\llvm-project\libcxx\test\std\utilities\memory\specialized.algorithms\uninitialized.copy\uninitialized_copy.pass.cpp:16:
In file included from D:\GitHub\STL\out\x64\out\inc\memory:14:
In file included from D:\GitHub\STL\out\x64\out\inc\xmemory:15:
D:\GitHub\STL\out\x64\out\inc\xutility(1344,58): error: invalid operands to binary expression ('const overload_compare_iterator<int *>' and 'const overload_compare_iterator<int *>')
        return static_cast<_Iter_diff_t<_Checked>>(_Last - _First);
                                                   ~~~~~ ^ ~~~~~~
D:\GitHub\STL\out\x64\out\inc\xmemory(1923,49): note: in instantiation of function template specialization 'std::_Idl_distance<overload_compare_iterator<int *>, overload_compare_iterator<int *>>' requested here
    auto _UDest       = _Get_unwrapped_n(_Dest, _Idl_distance<_InIt>(_UFirst, _ULast));
                                                ^
D:\GitHub\STL\llvm-project\libcxx\test\std\utilities\memory\specialized.algorithms\uninitialized.copy\uninitialized_copy.pass.cpp(100,18): note: in instantiation of function template specialization 'std::uninitialized_copy<overload_compare_iterator<int *>, int *>' requested here
            std::uninitialized_copy(Iterator(array), Iterator(array + N), p);
                 ^
1 error generated.
@github-actions github-actions bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 7, 2023
frederick-vs-ja added a commit that referenced this issue Oct 15, 2024
…12165)

`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.
bricknerb pushed a commit to bricknerb/llvm-project that referenced this issue Oct 16, 2024
…vm#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 llvm#74756.
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this issue Oct 16, 2024
…vm#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 llvm#74756.
bricknerb pushed a commit to bricknerb/llvm-project that referenced this issue Oct 17, 2024
…vm#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 llvm#74756.
EricWF pushed a commit to efcs/llvm-project that referenced this issue Oct 22, 2024
…vm#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 llvm#74756.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants