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

<algorithm>/<iterator>: contiguous iterators with non-ptrdiff_t difference types #3663

Closed
foonathan opened this issue Apr 19, 2023 · 6 comments · Fixed by #4898
Closed

<algorithm>/<iterator>: contiguous iterators with non-ptrdiff_t difference types #3663

foonathan opened this issue Apr 19, 2023 · 6 comments · Fixed by #4898
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@foonathan
Copy link

Describe the bug

We're having a contiguous iterator whose difference_type is int. STL algorithms then translate it to pointers and back, but doing so they e.g. call the iterator's operator- with a std::ptrdiff_t, not difference_type, like here:

return _Dest - (_LastPtr - _FirstPtr);

This causes a truncation warning.

Command-line test case

https://godbolt.org/z/YbojbWPMd

Expected behavior

No warning should happen, the implementation should cast to the appropriate difference type before invoking the operator.

STL version

Microsoft Visual Studio Professional 2022
Version 17.1.0
@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Apr 19, 2023

We have a number of issues on difference types. I guess there're also remain issues in <vector> , <deque>, and <xstring>.
CC @hewillk.

Edit: deque is likely to be fixed in #4049.

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Apr 19, 2023
@StephanTLavavej StephanTLavavej changed the title <algorithm>/<iterator>: contiguous iterators with non-ptrdiff_t difference types <algorithm>/<iterator>: contiguous iterators with non-ptrdiff_t difference types Apr 19, 2023
@hewillk
Copy link
Contributor

hewillk commented Oct 22, 2023

The issue occurs with _Copy_memmove too:

return _Dest + (_LastPtr - _FirstPtr);

Although I think the contiguous_iterator's difference type should at least have a width greater than or equal to ptrdiff_t.
testcase: https://godbolt.org/z/Tqhbs7j9v

@foonathan
Copy link
Author

We still run into this problem with std::copy_n: https://godbolt.org/z/Gvq7Pfr7E

@StephanTLavavej
Copy link
Member

@foonathan - Please open a new bug; commenting on closed bugs is hard to keep track of.

@frederick-vs-ja
Copy link
Contributor

We still run into this problem with std::copy_n: https://godbolt.org/z/Gvq7Pfr7E

It seems that the "latest" version used by Godbolt is currently 17.11.x, while the bugfix was merged for 17.12 Preview 3. So perhaps you need to update VS to get the bugfix at this moment.

@CaseyCarter
Copy link
Contributor

We still run into this problem with std::copy_n: https://godbolt.org/z/Gvq7Pfr7E

Fixed by #5046.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants