-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Closed
Labels
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.test-suite
Description
There's an overload_compare_iterator that wraps an Iterator and claims to have the same iterator_category:
llvm-project/libcxx/test/std/utilities/memory/specialized.algorithms/overload_compare_iterator.h
Lines 18 to 28 in 2b1c76c
| // 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
Labels
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.test-suite