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

--- Comment #1 from patrick at parcs dot ath.cx ---
We suppress the warning for

  int *p;

  void
  foo (int n)
  {
      if (p)
        foo (1);
      else   // guard token
      if (p) // body token
        foo (2);
      foo (3);  // next token
  }

because we notice that the guard, body and next tokens are all on the same
column.  But the closing brace in front of the "else" in the original test case
makes that condition no longer hold as the column of the guard token gets
shifted.

To fix this (and similar false positives), I think we should take into account
the first non-whitespace character on the guard line. If the column of that
character lines up with the columns of the body and next tokens, then we should
suppress the warning, too.  In the original test case the first nonwhitespace
character on the guard line is }, and indeed the columns line up.  So the
warning would be suppressed.


We also have to worry about the following false negative:

  int *p;

  void
  foo (int n)
  {
      if (p) {
        foo (1);
      } else  // guard
        if (p)  // body
          foo (2);
        foo (3); // next
  }

Here the guard, body and next columns line up, thus suppressing the warning --
but of course we would like to warn about "foo (3);" here.  So maybe we
shouldn't take into account the column of the guard character at all, but
rather always take into account the column of the first non-whitespace
character on the line of the guard token?

Reply via email to