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

--- Comment #7 from Marc Glisse <glisse at gcc dot gnu.org> ---
Reduced a bit more:

struct B {
  B();
  void m_fn2(int p1) {
    if (p1 <= storage_)
      throw;
  }
  int storage_;
};
void f() {
  B span_;
  int b = span_.storage_;
  span_.m_fn2(b - 1);
}

The warning seems correct to me (assuming the reduction didn't change things
too much). We have a comparison storage_ - 1 <= storage_, the compiler
optimizes it to true, and the warning tells you about it (maybe in the full
code the compiler would have a chance to prove that storage_ is never 0 and
thus storage_ - 1 can never overflow, but that's hard).

A warning doesn't necessary say that something is wrong with your code, here it
just informs you about an optimization. How useful that is is a different
question...

Reply via email to