public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110917] New: std::format_to(int*, ...) fails to compile because of _S_make_span
@ 2023-08-06 4:45 arthur.j.odwyer at gmail dot com
2023-08-06 21:37 ` [Bug libstdc++/110917] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2023-08-06 4:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917
Bug ID: 110917
Summary: std::format_to(int*, ...) fails to compile because of
_S_make_span
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: arthur.j.odwyer at gmail dot com
Target Milestone: ---
// https://godbolt.org/z/9onGvqfha
#include <format>
#include <list>
#include <vector>
void f(std::list<int>::iterator it) {
std::format_to(it, ""); // OK
}
void g(std::vector<int>::iterator it) {
std::format_to(it, ""); // boom!
}
libc++ and Microsoft are both completely happy with this code. libstdc++ is
happy with `f` but unhappy with `g`. I suspect that someplace is accepting
"contiguous iterators of any old T" when it means to limit itself to
"contiguous iterators of char" specifically.
In file included from <source>:1:
.../include/c++/14.0.0/format:2609:36: error: cannot initialize a parameter of
type 'char *' with an rvalue of type 'int *'
2609 | : _Sink<_CharT>(_S_make_span(std::to_address(__out), __n,
_M_buf)),
| ^~~~~~~~~~~~~~~~~~~~~~
.../include/c++/14.0.0/format:3641:32: note: in instantiation of member
function 'std::__format::_Iter_sink<char, __gnu_cxx::__normal_iterator<int *,
std::vector<int>>>::_Iter_sink' requested here
3641 | _Iter_sink<_CharT, _Out> __sink(std::move(__out));
| ^
.../include/c++/14.0.0/format:3683:24: note: in instantiation of function
template specialization
'std::__format::__do_vformat_to<__gnu_cxx::__normal_iterator<int *,
std::vector<int>>, char,
std::basic_format_context<std::__format::_Sink_iter<char>, char>>' requested
here
3683 | { return __format::__do_vformat_to(std::move(__out), __fmt,
__args); }
| ^
.../include/c++/14.0.0/format:3778:19: note: in instantiation of function
template specialization 'std::vformat_to<__gnu_cxx::__normal_iterator<int *,
std::vector<int>>>' requested here
3778 | return std::vformat_to(std::move(__out), __fmt.get(),
| ^
<source>:9:10: note: in instantiation of function template specialization
'std::format_to<__gnu_cxx::__normal_iterator<int *, std::vector<int>>>'
requested here
9 | std::format_to(it, "");
| ^
.../include/c++/14.0.0/format:2574:28: note: passing argument to parameter
'__ptr' here
2574 | _S_make_span(_CharT* __ptr, iter_difference_t<_OutIter> __n,
| ^
1 error generated.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span
2023-08-06 4:45 [Bug libstdc++/110917] New: std::format_to(int*, ...) fails to compile because of _S_make_span arthur.j.odwyer at gmail dot com
@ 2023-08-06 21:37 ` redi at gcc dot gnu.org
2023-08-07 14:33 ` arthur.j.odwyer at gmail dot com
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-08-06 21:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Last reconfirmed| |2023-08-06
Target Milestone|--- |13.3
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Arthur O'Dwyer from comment #0)
> libc++ and Microsoft are both completely happy with this code. libstdc++ is
> happy with `f` but unhappy with `g`. I suspect that someplace is accepting
> "contiguous iterators of any old T" when it means to limit itself to
> "contiguous iterators of char" specifically.
Indeed, it's fixed by:
// not introduce any invalid pointer arithmetic or overflows that would not
// have happened anyway.
template<typename _CharT, contiguous_iterator _OutIter>
+ requires same_as<iter_value_t<_OutIter>, _CharT>
class _Iter_sink<_CharT, _OutIter> : public _Sink<_CharT>
{
using uint64_t = __UINTPTR_TYPE__;
Alternatively, we could replace the contiguous_iterator<_OutIter> constraint
with constructible_from<span<_CharT>, _OutIter, iter_difference_t<_OutIter>>.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span
2023-08-06 4:45 [Bug libstdc++/110917] New: std::format_to(int*, ...) fails to compile because of _S_make_span arthur.j.odwyer at gmail dot com
2023-08-06 21:37 ` [Bug libstdc++/110917] " redi at gcc dot gnu.org
@ 2023-08-07 14:33 ` arthur.j.odwyer at gmail dot com
2023-08-07 14:42 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2023-08-07 14:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917
--- Comment #2 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
> Alternatively, we could replace the contiguous_iterator<_OutIter> constraint with constructible_from<span<_CharT>, _OutIter, iter_difference_t<_OutIter>>.
I think `is_same` is preferable to `constructible_from<...>` just because it's
simpler; I wouldn't recommend the hairier thing unless there was a known reason
for it. Doing the hairier thing would immediately trigger a search for the
corner case where it would fail. ;) (Suppose the author of _OutIter arranges
that sentinel_for<size_t, _OutIter> — maybe that'd do the trick...)
Btw, even though my reduced test case was contrived, it originates from an
actually realistic use-case AFAIK: using `format` to format ASCII text
automatically into an array of char16_t or char32_t (presumably on a platform
with unsigned plain char).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span
2023-08-06 4:45 [Bug libstdc++/110917] New: std::format_to(int*, ...) fails to compile because of _S_make_span arthur.j.odwyer at gmail dot com
2023-08-06 21:37 ` [Bug libstdc++/110917] " redi at gcc dot gnu.org
2023-08-07 14:33 ` arthur.j.odwyer at gmail dot com
@ 2023-08-07 14:42 ` redi at gcc dot gnu.org
2023-08-07 21:14 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-08-07 14:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It fails for non-contrived cases like this too:
char8_t buf[32];
std::format_to(buf, "");
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span
2023-08-06 4:45 [Bug libstdc++/110917] New: std::format_to(int*, ...) fails to compile because of _S_make_span arthur.j.odwyer at gmail dot com
` (2 preceding siblings ...)
2023-08-07 14:42 ` redi at gcc dot gnu.org
@ 2023-08-07 21:14 ` cvs-commit at gcc dot gnu.org
2023-08-08 16:13 ` cvs-commit at gcc dot gnu.org
2023-08-08 16:14 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-07 21:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917
--- Comment #4 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:c5ea5aecac323e9094e4dc967f54090cb244bc6a
commit r14-3068-gc5ea5aecac323e9094e4dc967f54090cb244bc6a
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Aug 7 14:37:25 2023 +0100
libstdc++: Constrain __format::_Iter_sink for contiguous iterators
[PR110917]
We can't write to a span<_CharT> if the contiguous iterator has a value
type that isn't _CharT.
libstdc++-v3/ChangeLog:
PR libstdc++/110917
* include/std/format (__format::_Iter_sink<CharT, OutIter>):
Constrain partial specialization for contiguous iterators to
require the value type to be CharT.
* testsuite/std/format/functions/format_to.cc: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span
2023-08-06 4:45 [Bug libstdc++/110917] New: std::format_to(int*, ...) fails to compile because of _S_make_span arthur.j.odwyer at gmail dot com
` (3 preceding siblings ...)
2023-08-07 21:14 ` cvs-commit at gcc dot gnu.org
@ 2023-08-08 16:13 ` cvs-commit at gcc dot gnu.org
2023-08-08 16:14 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-08 16:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:0f0152a93d15b24ebc7f6c7455baaded6a63fb2e
commit r13-7698-g0f0152a93d15b24ebc7f6c7455baaded6a63fb2e
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Aug 7 14:37:25 2023 +0100
libstdc++: Constrain __format::_Iter_sink for contiguous iterators
[PR110917]
We can't write to a span<_CharT> if the contiguous iterator has a value
type that isn't _CharT.
libstdc++-v3/ChangeLog:
PR libstdc++/110917
* include/std/format (__format::_Iter_sink<CharT, OutIter>):
Constrain partial specialization for contiguous iterators to
require the value type to be CharT.
* testsuite/std/format/functions/format_to.cc: New test.
(cherry picked from commit c5ea5aecac323e9094e4dc967f54090cb244bc6a)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span
2023-08-06 4:45 [Bug libstdc++/110917] New: std::format_to(int*, ...) fails to compile because of _S_make_span arthur.j.odwyer at gmail dot com
` (4 preceding siblings ...)
2023-08-08 16:13 ` cvs-commit at gcc dot gnu.org
@ 2023-08-08 16:14 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-08-08 16:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 13.3, thanks for the report.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-08-08 16:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-06 4:45 [Bug libstdc++/110917] New: std::format_to(int*, ...) fails to compile because of _S_make_span arthur.j.odwyer at gmail dot com
2023-08-06 21:37 ` [Bug libstdc++/110917] " redi at gcc dot gnu.org
2023-08-07 14:33 ` arthur.j.odwyer at gmail dot com
2023-08-07 14:42 ` redi at gcc dot gnu.org
2023-08-07 21:14 ` cvs-commit at gcc dot gnu.org
2023-08-08 16:13 ` cvs-commit at gcc dot gnu.org
2023-08-08 16:14 ` redi at gcc dot gnu.org
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).