Re: Possible GCC optimization bug

Jonathan Wakely via Gcc-help <[email protected]> Thu, 12 Feb 2026 18:05:16 +0000
Newsgroups gmane.comp.gcc.help
Message-ID <CAH6eHdRY6o4NmG=MYbBgxnf-8AvPgZV=bjAeuRtARtb96QWw_A@mail.gmail.com>
On Thu, 12 Feb 2026 at 17:46, Anubis 1101 <[email protected]> wrote:

> If you think it's walking past the end of the array, you definitely didn't
> read it.
>

(gdb) step
simpleString<10ul>::size (this=0x4054d8 <string>) at str.cc:163
163             std::size_t i = 0;
(gdb) n
165             while (data[i] != '\0'){i++;}
(gdb) n
str.cc:165:17: runtime error: index 10 out of bounds for type 'char [10]'
167             return &data[i]-&data[0];
(gdb) p i
$3 = 10
(gdb) whatis data
type = char [10]

So data[i] where i == 10 is not past the end of the array? Are you sure
about that?