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

--- Comment #2 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Thanks.

I ran into a variant of this whilst testing -Wmisleading-indentation on the
linux kernel, where a preprocessor macro conditionalizes the "if/else"; here's
the test case I reduced it to:

/* This variant of K&R-style formatting (in the presence of conditional
   compilation) shouldn't lead to a warning.

   Based on false positive seen with r223098 when compiling
   linux-4.0.3:arch/x86/crypto/aesni-intel_glue.c:aesni_init.  */

void
fn_36 (void)
{
#if 1 /* e.g. some configuration variable.  */
        if (flagA) {
                foo(0);
                foo(1);
                foo(2);
        } else
#endif
        {
                foo(3);
                foo(4);
                foo(5);
        }
        foo(6); /* We shouldn't warn here.  */
}

I have a fix for this, by requiring that the visual column of the guard
("else") be <= that of the stmts, which works for all of the testcases
(including the new ones I posted as
https://gcc.gnu.org/ml/gcc-patches/2015-05/msg01846.html ), apart from fn_15:

#define FOR_EACH(VAR, START, STOP) for ((VAR) = (START); (VAR) < (STOP);
(VAR++)) /* { dg-message "36: ...this 'for' clause, but it is not" } */
void fn_15 (void)
{
  int i;
  FOR_EACH (i, 0, 10) /* { dg-message "3: in expansion of macro" } */
    foo (i);
    bar (i, i); /* { dg-warning "statement is indented as if it were guarded
by..." } */
}
#undef FOR_EACH

which then fails to report the warning due to it using the location of the
"for" in the defn of macro FOR_EACH.

Fixing that will require some reworking on how we handle macro expansions.

Reply via email to