On Thu, Mar 3, 2016 at 10:21 AM, David Malcolm <dmalc...@redhat.com> wrote: > Comment #1 of PR c/68187 identified another overzealous warning > from -Wmisleading-indentation, with OpenSSL 1.0.1, on this poorly > indented code: > > 115 if (locked) > 116 i = CRYPTO_add(&e->struct_ref, -1, CRYPTO_LOCK_ENGINE); > 117 else > 118 i = --e->struct_ref; > 119 engine_ref_debug(e, 0, -1) > 120 if (i > 0) > 121 return 1; > > eng_lib.c:120:9: warning: statement is indented as if it were guarded by... > [-Wmisleading-indentation] > if (i > 0) > ^~ > eng_lib.c:117:5: note: ...this 'else' clause, but it is not > else > ^~~~ > > Line 120 is poorly indented, but the warning is arguably unjustified. > > Root cause is that "engine_ref_debug" is actually a debugging macro > that was empty in the given configuration, so the code effectively > was: > > 117 else // GUARD > 118 i = --e->struct_ref; // BODY > 119 > 120 if (i > 0) // NEXT > > hence the warning. > > But the code as seen by a human is clearly *not* misleading, and > hence arguably we shouldn't warn for this case. > > The following patch fixes this by ruling that if there is non-whitespace > in a line between the BODY and the NEXT statements, and that this > non-whitespace is effectively an "unindent" or "outdent" (it's not clear > to me which of these terms is better), then to not issue a warning.
Cool, this also fixes the false-positives seen in bdwgc, whose coding style suggests indenting things inside an #ifdef as if it were an if(), e.g.: if (a) foo (); # ifndef A bar (); # endif ...