зеркало из https://github.com/microsoft/STL.git
Avoid truncation warnings for contiguous iterators with unusual difference types (#4898)
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
This commit is contained in:
Родитель
20a1c9f0d2
Коммит
d5777f4fef
|
@ -4659,7 +4659,7 @@ _OutCtgIt _Copy_memmove(_CtgIt _First, _CtgIt _Last, _OutCtgIt _Dest) {
|
|||
if constexpr (is_pointer_v<_OutCtgIt>) {
|
||||
return reinterpret_cast<_OutCtgIt>(_Dest_ch + _Count);
|
||||
} else {
|
||||
return _Dest + (_LastPtr - _FirstPtr);
|
||||
return _Dest + static_cast<_Iter_diff_t<_OutCtgIt>>(_LastPtr - _FirstPtr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4984,7 +4984,7 @@ _CtgIt2 _Copy_backward_memmove(_CtgIt1 _First, _CtgIt1 _Last, _CtgIt2 _Dest) {
|
|||
if constexpr (is_pointer_v<_CtgIt2>) {
|
||||
return static_cast<_CtgIt2>(_Result);
|
||||
} else {
|
||||
return _Dest - (_LastPtr - _FirstPtr);
|
||||
return _Dest - static_cast<_Iter_diff_t<_CtgIt2>>(_LastPtr - _FirstPtr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -230,6 +230,7 @@ tests\GH_003119_error_category_ctor
|
|||
tests\GH_003246_cmath_narrowing
|
||||
tests\GH_003570_allocate_at_least
|
||||
tests\GH_003617_vectorized_meow_element
|
||||
tests\GH_003663_cast_contiguous_iterator_difference_type
|
||||
tests\GH_003676_format_large_hh_mm_ss_values
|
||||
tests\GH_003735_char_traits_signatures
|
||||
tests\GH_003840_tellg_when_reading_lf_file_in_text_mode
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
RUNALL_INCLUDE ..\usual_20_matrix.lst
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
class ContiguousIterator {
|
||||
public:
|
||||
using value_type = int;
|
||||
using difference_type = int;
|
||||
using element_type = int;
|
||||
using iterator_category = std::contiguous_iterator_tag;
|
||||
int* operator->() const;
|
||||
int& operator*() const;
|
||||
int& operator[](int) const;
|
||||
ContiguousIterator& operator++();
|
||||
ContiguousIterator operator++(int);
|
||||
ContiguousIterator& operator--();
|
||||
ContiguousIterator operator--(int);
|
||||
ContiguousIterator& operator+=(int);
|
||||
ContiguousIterator& operator-=(int);
|
||||
friend auto operator<=>(ContiguousIterator, ContiguousIterator) = default;
|
||||
friend int operator-(ContiguousIterator, ContiguousIterator);
|
||||
friend ContiguousIterator operator+(ContiguousIterator, int);
|
||||
friend ContiguousIterator operator-(ContiguousIterator, int);
|
||||
friend ContiguousIterator operator+(int, ContiguousIterator);
|
||||
};
|
||||
|
||||
static_assert(std::contiguous_iterator<ContiguousIterator>);
|
||||
|
||||
// GH-3663 <algorithm>/<iterator>: contiguous iterators with non-ptrdiff_t difference types
|
||||
void test() {
|
||||
int* p = nullptr;
|
||||
std::copy(p, p, ContiguousIterator{});
|
||||
std::sort(ContiguousIterator{}, ContiguousIterator{});
|
||||
}
|
Загрузка…
Ссылка в новой задаче