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

--- Comment #4 from 康桓瑋 <hewillk at gmail dot com> ---
When the array subscript is outside the bounds of array, gcc seems to fall into
infinite recursion due to the default operator==.

Here is the reduced with no header:

struct A {
  constexpr A(const char*) {}
  char value[1] = {};
};

template <A>
struct B {
  constexpr bool operator==(const B&) const = default;
};

constexpr auto foo(auto) {
  constexpr auto a = [] {
    char value[1];
    value[2] = 0; // this line
    return A{value};
  }();
  return B<a>{};
}

constexpr auto b = foo(B<"">{});

<source>: In instantiation of 'struct B<<expression error> >':
<source>:8:18:   recursively required from 'struct B<<expression error> >'
<source>:8:18:   required from 'struct B<<expression error> >'
<source>:17:15:   required from 'constexpr auto foo(auto:1) [with auto:1 =
B<A{""}>]'
<source>:20:23:   required from here
<source>:8:18: fatal error: template instantiation depth exceeds maximum of 900
(use '-ftemplate-depth=' to increase the maximum)
    8 |   constexpr bool operator==(const B&) const = default;
      |                  ^~~~~~~~
compilation terminated.

Reply via email to