Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@StephanTLavavej
Copy link
Member

Test coverage will be provided by std/strings/basic.string/string.cons/from_range.pass.cpp, std/containers/unord/unord.multimap/unord.multimap.cnstr/from_range.pass.cpp, and more in the upcoming libcxx update that I'm working on. They have allocators with custom size/difference types (e.g. 32-bit types even on 64-bit platforms) that reveal these issues.

When subtracting string/vector iterators, we can get truncation warnings like xstring(1972): warning C4244: 'return': conversion from '__int64' to 'int', possible loss of data. Because we're subtracting iterators into the same string/vector, casting to the allocator's difference_type is always safe.

In _Is_permutation_sized powering ranges::is_permutation, we can get algorithm(940): warning C4244: 'argument': conversion from '__int64' to 'const int', possible loss of data. This happens when the ranges have different difference types. We call _Is_permutation_sized after checking that the ranges are the same length, so we only pass the first count, and casting that to the second range's difference type is guaranteed to be value-preserving. This asymmetry looked strange enough that I thought it deserved a comment (even without introducing using _Diff2, the line would get long enough to wrap, so we have space for a comment anyways).

… iterators.

Found by std/strings/basic.string/string.cons/from_range.pass.cpp.

xstring(1972): warning C4244: 'return': conversion from '__int64' to 'int', possible loss of data

Because we're subtracting iterators into the same string, the allocator's difference_type is always safe.

Same issue with vectors.
std/containers/unord/unord.multimap/unord.multimap.cnstr/from_range.pass.cpp

algorithm(940): warning C4244: 'argument': conversion from '__int64' to 'const int', possible loss of data
@StephanTLavavej StephanTLavavej added bug Something isn't working ranges C++20/23 ranges labels Dec 4, 2023
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner December 4, 2023 22:42
@StephanTLavavej StephanTLavavej self-assigned this Dec 7, 2023
@StephanTLavavej
Copy link
Member Author

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit ae50dff into microsoft:main Dec 7, 2023
@StephanTLavavej StephanTLavavej deleted the truncation-warnings branch December 7, 2023 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ranges C++20/23 ranges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants