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

Avoid truncation warnings for contiguous iterators with unusual difference types #4898

Merged
merged 5 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -4658,7 +4658,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);
}
}

Expand Down Expand Up @@ -4983,7 +4983,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);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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_to_correct_type
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_20_matrix.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <algorithm>
#include <iterator>

class contiguous_iterator {
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
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;
contiguous_iterator& operator++();
contiguous_iterator operator++(int);
contiguous_iterator& operator--();
contiguous_iterator operator--(int);
contiguous_iterator& operator+=(int);
contiguous_iterator& operator-=(int);
friend auto operator<=>(contiguous_iterator, contiguous_iterator) = default;
friend int operator-(contiguous_iterator, contiguous_iterator);
friend contiguous_iterator operator+(contiguous_iterator, int);
friend contiguous_iterator operator-(contiguous_iterator, int);
friend contiguous_iterator operator+(int, contiguous_iterator);
};

// GH-3663 <algorithm>/<iterator>: contiguous iterators with non-ptrdiff_t difference types
int main() {
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
int* p = nullptr;
std::copy(p, p, contiguous_iterator{});
std::sort(contiguous_iterator{}, contiguous_iterator{});
}