https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123515
Bug ID: 123515
Summary: warning inside libstdc++ : array subscript 1 is
outside array bounds
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: franckbehaghel_gcc at protonmail dot com
Target Milestone: ---
The following source with flags "-O2 -Wall -std=c++20" produces no warning with
gcc 15.2 , but give a warning with gcc 16 : array subscript 1 is outside array
bounds.
https://godbolt.org/z/EoMqj9EWb
File and output :
#include <format>
#include <string>
#include <iostream>
int main( )
{
int x = 1;
std::string txt = std::format("x {}", x);
std::cout << txt << std::endl;
return 0;
}
Full output :
In file included from
/cefs/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/include/c++/16.0.0/bits/stl_algobase.h:66,
from
/cefs/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/include/c++/16.0.0/array:45,
from
/cefs/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/include/c++/16.0.0/format:860:27:
/cefs/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/include/c++/16.0.0/format:860:27:
/cefs/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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/5c/5c001bbe76120b5dfbea78e5_gcc-trunk-20260108/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 };
| ^~~~~
Compiler returned: 0