[Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span

2023-08-08 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917

Jonathan Wakely  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #6 from Jonathan Wakely  ---
Fixed for 13.3, thanks for the report.

[Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span

2023-08-08 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917

--- Comment #5 from CVS Commits  ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
:

https://gcc.gnu.org/g:0f0152a93d15b24ebc7f6c7455baaded6a63fb2e

commit r13-7698-g0f0152a93d15b24ebc7f6c7455baaded6a63fb2e
Author: Jonathan Wakely 
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):
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)

[Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span

2023-08-07 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917

--- Comment #4 from CVS Commits  ---
The master branch has been updated by Jonathan Wakely :

https://gcc.gnu.org/g:c5ea5aecac323e9094e4dc967f54090cb244bc6a

commit r14-3068-gc5ea5aecac323e9094e4dc967f54090cb244bc6a
Author: Jonathan Wakely 
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):
Constrain partial specialization for contiguous iterators to
require the value type to be CharT.
* testsuite/std/format/functions/format_to.cc: New test.

[Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span

2023-08-07 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917

--- Comment #3 from Jonathan Wakely  ---
It fails for non-contrived cases like this too:

char8_t buf[32];
std::format_to(buf, "");

[Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span

2023-08-07 Thread arthur.j.odwyer at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917

--- Comment #2 from Arthur O'Dwyer  ---
> Alternatively, we could replace the contiguous_iterator<_OutIter> constraint 
> with constructible_from, _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 — 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).

[Bug libstdc++/110917] std::format_to(int*, ...) fails to compile because of _S_make_span

2023-08-06 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110917

Jonathan Wakely  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  ---
(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
+requires same_as, _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, _OutIter, iter_difference_t<_OutIter>>.