https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107986

Artur Sharafutdinov <asharafutdinov at adalisk dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |asharafutdinov at adalisk dot 
com

--- Comment #10 from Artur Sharafutdinov <asharafutdinov at adalisk dot com> ---
Similar bug affects all GCC versions starting from 10.1.

#include <algorithm>

struct A
{
    int n = 0;
};

bool operator <(const A &a, const A &b)
{
    return a.n < b.n;
}

int main()
{
    // both values may vary in range [3; 8]
    constexpr int N = 8;
    constexpr int M = 3;
    A a[N];
    for (auto i = 1; i <= M; ++i)
        std::sort(a, a + i);
}

Being built with -std=c++20 -Wall -Werror -O3, it gives the error:

<source>: In function 'int main()':
<source>:10:20: error: array subscript [8, 1152921504606846975] is outside
array bounds of 'A [8]' [-Werror=array-bounds]
   10 |     return a.n < b.n;
      |                  ~~^
<source>:17:7: note: while referencing 'a'
   17 |     A a[N];
      |       ^

Reply via email to