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

            Bug ID: 91168
           Summary: -Warray-bounds in valid program
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: grishalipenko at protonmail dot com
  Target Milestone: ---

Compile: g++ -Wall -Wextra -O2 -Werror -c main.cpp

class S
{
private:
  double *x;
  double d;
  unsigned int N;
public:
  int g (const double *b, int N_)
    {
      N = N_;
      x = new double[N];
      for (unsigned int i = 1; i < N - 1; i++)
        {
          d = b[i + 1];
        }
      return 0;
    }
};

class A
{
  S s;
public:
  int f ();
};

int A::f ()
{
  constexpr int N = 2;
  double a[N] = {0., 0.};
  s.g (a, N);
  return 0;
}

No warning if compile with gcc 8.3.0 .

Reply via email to