[Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871 --- Comment #8 from 康桓瑋 --- (In reply to Jonathan Wakely from comment #4) > Maybe you could legally do: > > using difference_type = iterator_t>; > > but maybe just don't do that. If things break when you do dumb things, don't > do those things. A more uncontrived example would be: std::vector v(10); auto r = std::views::iota((unsigned __int128)0) | std::views::transform([&](auto i) -> auto& { return v[i]; }); auto s = std::format_to_n(r.begin(), 5, "{}", "");
[Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |FIXED --- Comment #7 from Jonathan Wakely --- Oh yes, I wonder why I bothered handling it there :-) It should be fixed now, thanks for the report.
[Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871 --- Comment #6 from CVS Commits --- The master branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:9cce91a63dcc40cb39e68f6a771e891e51c51946 commit r13-4527-g9cce91a63dcc40cb39e68f6a771e891e51c51946 Author: Jonathan Wakely Date: Mon Dec 5 21:38:53 2022 + libstdc++: Add casts for integer-like difference type [PR107871] libstdc++-v3/ChangeLog: PR libstdc++/107871 * include/std/format (_Iter_sink::_M_overflow): Add cast to size_t. (_Iter_sink::_M_make_span): Use typedef instead of decltype. * testsuite/std/format/functions/107871.cc: New test.
[Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871 --- Comment #5 from 康桓瑋 --- (In reply to Jonathan Wakely from comment #4) > Maybe you could legally do: > > using difference_type = iterator_t>; > > but maybe just don't do that. If things break when you do dumb things, don't > do those things. I would never do that. However, I see that you seem to have considered this issue elsewhere, in format#L2561: if constexpr (!is_integral_v || sizeof(__n) > sizeof(size_t)) { // __int128 or __detail::__max_diff_type auto __m = (decltype(__n))(size_t)-1; if (__n > __m) __n = __m; }
[Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871 --- Comment #4 from Jonathan Wakely --- Maybe you could legally do: using difference_type = iterator_t>; but maybe just don't do that. If things break when you do dumb things, don't do those things.
[Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871 --- Comment #3 from Jonathan Wakely --- No. They are only allowed to be implementation-defined types, not program-defined types. I can add the casts to make this work, but I don't think it's a real problem that can occur in valid programs.
[Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871 --- Comment #2 from 康桓瑋 --- This is just an example. So, are users not allowed to define integer-like class types?
[Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871 --- Comment #1 from Jonathan Wakely --- This isn't valid code, you can't use max diff type for your own types. It can only be used by the library for iota_view, but that doesn't have output iterators.