This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Refactor -Wmisleading-indentation API and extend coverage
- From: Patrick Palka <patrick at parcs dot ath dot cx>
- To: Patrick Palka <patrick at parcs dot ath dot cx>
- Cc: gcc-patches at gcc dot gnu dot org, joseph at codesourcery dot com, jason at redhat dot com, dmalcolm at redhat dot com
- Date: Sun, 7 Jun 2015 19:09:27 -0400 (EDT)
- Subject: Re: [PATCH] Refactor -Wmisleading-indentation API and extend coverage
- Authentication-results: sourceware.org; auth=none
- References: <1433707596-6988-1-git-send-email-patrick at parcs dot ath dot cx>
The new heuristic turns out to trigger a common false positive (see test
case below) in many programs. I have applied this diff on top of the
original patch to make the heuristic more strict.
diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-indentation.c
index d3e842b..5532ff4 100644
--- a/gcc/c-family/c-indentation.c
+++ b/gcc/c-family/c-indentation.c
@@ -390,7 +390,10 @@ should_warn_for_misleading_indentation (const common_token_info &guard_tinfo,
unsigned int guard_vis_column;
if (!get_visual_column (guard_exploc, &guard_vis_column))
return false;
- if (next_stmt_vis_column != guard_vis_column
+ if (next_stmt_vis_column > guard_vis_column
+ || (guard_tinfo.keyword == RID_IF
+ && next_stmt_vis_column < guard_vis_column
+ && !is_first_nonwhitespace_on_line (guard_exploc))
|| (next_tok_type == CPP_OPEN_BRACE
&& next_stmt_vis_column == guard_vis_column))
return true;
diff --git a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c
index e8e04e3..fd25102 100644
--- a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c
+++ b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c
@@ -787,6 +787,13 @@ fn_37 (void)
foo (3);
}
+ if (i)
+ while (i++ < 10000);
+ foo (5);
+
+ if (i) while (i++ < 10000);
+ foo (5);
+
#undef EMPTY
#undef FOR_EACH
}