`<format>`: `format_to_n` missing difference type casting
Open
Nobody has claimed this yet.
bug
format
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
This bug belongs to difference type casting category.
The type of _Max is iter_difference_t<O>, but the parameter type of _Fmt_iterator_buffer is ptrdiff_t, which does not guarantee that it can be implicitly converted by the former.
contrived testcase:
#include <ranges>
#include <format>
#include <vector>
#include <iostream>
int main() {
std::vector<char> v(10);
auto r = std::views::iota(0ULL) |
std::views::transform([&](std::size_t i) -> auto& { return v[i]; });
auto str = std::format_to_n(r.begin(), 5, "{}", "hello");
std::cout << v.data() << "\n";
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at stl/inc/format around lines 3551-3557 and compare the _Max and _Fmt_iterator_buffer parameter types with the provided format_to_n testcase. Verify the corrected difference-type handling using that testcase and confirm the formatting behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100