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.

Reply via email to