https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123402
Bug ID: 123402
Summary: Annoying warnings for weeks using gcc trunk and
format() and -O2 and -Wall
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nico at josuttis dot de
Target Milestone: ---
For several weeks there is now an annoying warning in the gcc trunk.
Would be great to get this fixed.
See https://www.godbolt.org/z/5W155neW9.
Just compiling this code:
#include <format>
auto foo()
{
return std::format("{}\n", 42);
}
and compiling with
-std=c++20 -O2 -Wall
results in this huge warning:
In file included from
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/stl_algobase.h:66,
from
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/array:45,
from
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/format:46,
from <source>:1:
In member function 'constexpr __gnu_cxx::__normal_iterator<_Iterator,
_Container> __gnu_cxx::__normal_iterator<_Iterator,
_Container>::operator++(int) [with _Iterator = const char32_t*; _Container =
std::span<const char32_t, 1>::__iter_tag]',
inlined from 'constexpr void std::__unicode::_Utf_iterator<_FromFmt,
_ToFmt, _Iter, _Sent, _ErrorHandler>::_M_read_utf32() [with _FromFmt =
char32_t; _ToFmt = char; _Iter = __gnu_cxx::__normal_iterator<const char32_t*,
std::span<const char32_t, 1>::__iter_tag>; _Sent =
__gnu_cxx::__normal_iterator<const char32_t*, std::span<const char32_t,
1>::__iter_tag>; _ErrorHandler = std::__unicode::_Repl]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:440:27,
inlined from 'constexpr void std::__unicode::_Utf_iterator<_FromFmt,
_ToFmt, _Iter, _Sent, _ErrorHandler>::_M_read() [with _FromFmt = char32_t;
_ToFmt = char; _Iter = __gnu_cxx::__normal_iterator<const char32_t*,
std::span<const char32_t, 1>::__iter_tag>; _Sent =
__gnu_cxx::__normal_iterator<const char32_t*, std::span<const char32_t,
1>::__iter_tag>; _ErrorHandler = std::__unicode::_Repl]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:272:19,
inlined from 'constexpr std::__unicode::_Utf_iterator<_FromFmt, _ToFmt,
_Iter, _Sent, _ErrorHandler>::_Utf_iterator(_Iter, _Iter, _Sent) requires
bidirectional_iterator<_Iter> [with _FromFmt = char32_t; _ToFmt = char; _Iter =
__gnu_cxx::__normal_iterator<const char32_t*, std::span<const char32_t,
1>::__iter_tag>; _Sent = __gnu_cxx::__normal_iterator<const char32_t*,
std::span<const char32_t, 1>::__iter_tag>; _ErrorHandler =
std::__unicode::_Repl]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:132:11,
inlined from 'constexpr auto std::__unicode::_Utf_view<_ToFormat,
_View>::_M_end(_Iter, _Sent) [with _Iter = __gnu_cxx::__normal_iterator<const
char32_t*, std::span<const char32_t, 1>::__iter_tag>; _Sent =
__gnu_cxx::__normal_iterator<const char32_t*, std::span<const char32_t,
1>::__iter_tag>; _ToFormat = char; _View = std::span<const char32_t, 1>]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:724:46,
inlined from 'constexpr auto std::__unicode::_Utf_view<_ToFormat,
_View>::end() [with _ToFormat = char; _View = std::span<const char32_t, 1>]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:739:22,
inlined from '_Out std::__format::__write_padded(_Out,
std::basic_string_view<_CharT>, _Align, std::size_t, char32_t) [with _Out =
_Sink_iter<char>; _CharT = char]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/format:860:27:
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/stl_iterator.h:1111:16:
warning: array subscript 2 is outside array bounds of 'const char32_t [1]'
[-Warray-bounds=]
1111 | { return __normal_iterator(_M_current++); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/format:
In function '_Out std::__format::__write_padded(_Out,
std::basic_string_view<_CharT>, _Align, std::size_t, char32_t) [with _Out =
_Sink_iter<char>; _CharT = char]':
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/format:858:28:
note: at offset 8 into object '__arr' of size 4
858 | const char32_t __arr[1]{ __fill_char };
| ^~~~~
In file included from
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/format:62:
In member function 'constexpr void std::__unicode::_Utf_iterator<_FromFmt,
_ToFmt, _Iter, _Sent, _ErrorHandler>::_M_read_utf32() [with _FromFmt =
char32_t; _ToFmt = char; _Iter = __gnu_cxx::__normal_iterator<const char32_t*,
std::span<const char32_t, 1>::__iter_tag>; _Sent =
__gnu_cxx::__normal_iterator<const char32_t*, std::span<const char32_t,
1>::__iter_tag>; _ErrorHandler = std::__unicode::_Repl]',
inlined from 'constexpr void std::__unicode::_Utf_iterator<_FromFmt,
_ToFmt, _Iter, _Sent, _ErrorHandler>::_M_read() [with _FromFmt = char32_t;
_ToFmt = char; _Iter = __gnu_cxx::__normal_iterator<const char32_t*,
std::span<const char32_t, 1>::__iter_tag>; _Sent =
__gnu_cxx::__normal_iterator<const char32_t*, std::span<const char32_t,
1>::__iter_tag>; _ErrorHandler = std::__unicode::_Repl]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:272:19,
inlined from 'constexpr std::__unicode::_Utf_iterator<_FromFmt, _ToFmt,
_Iter, _Sent, _ErrorHandler>::_Utf_iterator(_Iter, _Iter, _Sent) requires
bidirectional_iterator<_Iter> [with _FromFmt = char32_t; _ToFmt = char; _Iter =
__gnu_cxx::__normal_iterator<const char32_t*, std::span<const char32_t,
1>::__iter_tag>; _Sent = __gnu_cxx::__normal_iterator<const char32_t*,
std::span<const char32_t, 1>::__iter_tag>; _ErrorHandler =
std::__unicode::_Repl]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:132:11,
inlined from 'constexpr auto std::__unicode::_Utf_view<_ToFormat,
_View>::_M_end(_Iter, _Sent) [with _Iter = __gnu_cxx::__normal_iterator<const
char32_t*, std::span<const char32_t, 1>::__iter_tag>; _Sent =
__gnu_cxx::__normal_iterator<const char32_t*, std::span<const char32_t,
1>::__iter_tag>; _ToFormat = char; _View = std::span<const char32_t, 1>]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:724:46,
inlined from 'constexpr auto std::__unicode::_Utf_view<_ToFormat,
_View>::end() [with _ToFormat = char; _View = std::span<const char32_t, 1>]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:739:22,
inlined from '_Out std::__format::__write_padded(_Out,
std::basic_string_view<_CharT>, _Align, std::size_t, char32_t) [with _Out =
_Sink_iter<char>; _CharT = char]' at
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/format:860:27:
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/bits/unicode.h:440:18:
warning: array subscript 1 is outside array bounds of 'const char32_t [1]'
[-Warray-bounds=]
440 | char32_t __c = *_M_curr()++;
| ^~~
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/format:
In function '_Out std::__format::__write_padded(_Out,
std::basic_string_view<_CharT>, _Align, std::size_t, char32_t) [with _Out =
_Sink_iter<char>; _CharT = char]':
/cefs/29/29b4e802ce41b2060562b261_gcc-trunk-20260105/include/c++/16.0.0/format:858:28:
note: at offset 4 into object '__arr' of size 4
858 | const char32_t __arr[1]{ __fill_char };
| ^~~~~