Skip to content

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

@foonathan

Description

@foonathan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions