This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Refactor -Wmisleading-indentation API and extend coverage


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
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]