public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting
@ 2022-11-25 18:58 hewillk at gmail dot com
2022-11-25 22:19 ` [Bug libstdc++/107871] " redi at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2022-11-25 18:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871
Bug ID: 107871
Summary: _Iter_sink:: _M_overflow missing some difference type
casting
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
#include <format>
struct O {
using difference_type = std::ranges::__detail::__max_diff_type;
O& operator=(const char&);
O& operator*();
O& operator++();
O& operator++(int);
};
int main() {
std::format_to_n(O{}, 4, "{}", " ");
}
https://godbolt.org/z/x78qjfse6
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
2022-11-25 18:58 [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting hewillk at gmail dot com
@ 2022-11-25 22:19 ` redi at gcc dot gnu.org
2022-11-26 11:28 ` hewillk at gmail dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-25 22:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
2022-11-25 18:58 [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting hewillk at gmail dot com
2022-11-25 22:19 ` [Bug libstdc++/107871] " redi at gcc dot gnu.org
@ 2022-11-26 11:28 ` hewillk at gmail dot com
2022-11-26 14:51 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2022-11-26 11:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871
--- Comment #2 from 康桓瑋 <hewillk at gmail dot com> ---
This is just an example. So, are users not allowed to define integer-like class
types?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
2022-11-25 18:58 [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting hewillk at gmail dot com
2022-11-25 22:19 ` [Bug libstdc++/107871] " redi at gcc dot gnu.org
2022-11-26 11:28 ` hewillk at gmail dot com
@ 2022-11-26 14:51 ` redi at gcc dot gnu.org
2022-11-26 14:53 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-26 14:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
2022-11-25 18:58 [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting hewillk at gmail dot com
` (2 preceding siblings ...)
2022-11-26 14:51 ` redi at gcc dot gnu.org
@ 2022-11-26 14:53 ` redi at gcc dot gnu.org
2022-12-05 18:05 ` hewillk at gmail dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-26 14:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Maybe you could legally do:
using difference_type = iterator_t<iota_view<__int128, __int128>>;
but maybe just don't do that. If things break when you do dumb things, don't do
those things.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
2022-11-25 18:58 [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting hewillk at gmail dot com
` (3 preceding siblings ...)
2022-11-26 14:53 ` redi at gcc dot gnu.org
@ 2022-12-05 18:05 ` hewillk at gmail dot com
2022-12-06 21:40 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2022-12-05 18:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871
--- Comment #5 from 康桓瑋 <hewillk at gmail dot com> ---
(In reply to Jonathan Wakely from comment #4)
> Maybe you could legally do:
>
> using difference_type = iterator_t<iota_view<__int128, __int128>>;
>
> 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<decltype(__n)>
|| sizeof(__n) > sizeof(size_t))
{
// __int128 or __detail::__max_diff_type
auto __m = (decltype(__n))(size_t)-1;
if (__n > __m)
__n = __m;
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
2022-11-25 18:58 [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting hewillk at gmail dot com
` (4 preceding siblings ...)
2022-12-05 18:05 ` hewillk at gmail dot com
@ 2022-12-06 21:40 ` cvs-commit at gcc dot gnu.org
2022-12-06 21:42 ` redi at gcc dot gnu.org
2022-12-07 11:42 ` hewillk at gmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-06 21:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:9cce91a63dcc40cb39e68f6a771e891e51c51946
commit r13-4527-g9cce91a63dcc40cb39e68f6a771e891e51c51946
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Dec 5 21:38:53 2022 +0000
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<CharT, contiguous_iterator auto>::_M_make_span): Use
typedef instead of decltype.
* testsuite/std/format/functions/107871.cc: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
2022-11-25 18:58 [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting hewillk at gmail dot com
` (5 preceding siblings ...)
2022-12-06 21:40 ` cvs-commit at gcc dot gnu.org
@ 2022-12-06 21:42 ` redi at gcc dot gnu.org
2022-12-07 11:42 ` hewillk at gmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-12-06 21:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Oh yes, I wonder why I bothered handling it there :-)
It should be fixed now, thanks for the report.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/107871] _Iter_sink:: _M_overflow missing some difference type casting
2022-11-25 18:58 [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting hewillk at gmail dot com
` (6 preceding siblings ...)
2022-12-06 21:42 ` redi at gcc dot gnu.org
@ 2022-12-07 11:42 ` hewillk at gmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2022-12-07 11:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107871
--- Comment #8 from 康桓瑋 <hewillk at gmail dot com> ---
(In reply to Jonathan Wakely from comment #4)
> Maybe you could legally do:
>
> using difference_type = iterator_t<iota_view<__int128, __int128>>;
>
> 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<char> 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, "{}", "");
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-12-07 11:42 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-25 18:58 [Bug libstdc++/107871] New: _Iter_sink:: _M_overflow missing some difference type casting hewillk at gmail dot com
2022-11-25 22:19 ` [Bug libstdc++/107871] " redi at gcc dot gnu.org
2022-11-26 11:28 ` hewillk at gmail dot com
2022-11-26 14:51 ` redi at gcc dot gnu.org
2022-11-26 14:53 ` redi at gcc dot gnu.org
2022-12-05 18:05 ` hewillk at gmail dot com
2022-12-06 21:40 ` cvs-commit at gcc dot gnu.org
2022-12-06 21:42 ` redi at gcc dot gnu.org
2022-12-07 11:42 ` hewillk at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).