Skip to content

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

@StephanTLavavej

Description

@StephanTLavavej

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.test-suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions