summaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-03-04 15:45:19 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-03-04 15:45:19 +0000
commit74c6fd40a953e2ad1657d06946994d51ec8a64e0 (patch)
tree437b3b6b9215076f13844d2bc99227445a912367 /gcc/c-family
parent31b1135939e123d84a548e433892eff6c1818a63 (diff)
downloadgcc-74c6fd40a953e2ad1657d06946994d51ec8a64e0.tar.gz
PR c/68187: fix overzealous -Wmisleading-indentation (comment #0)
gcc/c-family/ChangeLog: PR c/68187 * c-indentation.c (should_warn_for_misleading_indentation): When suppressing warnings about cases where the guard and body are on the same column, only use the first non-whitespace column in place of the guard token column when dealing with "else" clauses. When rejecting aligned BODY and NEXT, loosen the requirement from equality with the first non-whitespace of guard to simply that they not be indented relative to it. gcc/testsuite/ChangeLog: PR c/68187 * c-c++-common/Wmisleading-indentation.c (fn_40_a): New test function. (fn_40_b): Likewise. (fn_41_a): Likewise. (fn_41_b): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233971 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog11
-rw-r--r--gcc/c-family/c-indentation.c16
2 files changed, 21 insertions, 6 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 5c777b6ecee..fa728f06238 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,14 @@
+2016-03-04 David Malcolm <dmalcolm@redhat.com>
+
+ PR c/68187
+ * c-indentation.c (should_warn_for_misleading_indentation): When
+ suppressing warnings about cases where the guard and body are on
+ the same column, only use the first non-whitespace column in place
+ of the guard token column when dealing with "else" clauses.
+ When rejecting aligned BODY and NEXT, loosen the requirement
+ from equality with the first non-whitespace of guard to simply
+ that they not be indented relative to it.
+
2016-03-04 Richard Biener <rguenther@suse.de>
PR c++/70054
diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-indentation.c
index 521f9924fd0..c72192d9e0a 100644
--- a/gcc/c-family/c-indentation.c
+++ b/gcc/c-family/c-indentation.c
@@ -419,7 +419,8 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo,
{
/* Don't warn if they are aligned on the same column
as the guard itself (suggesting autogenerated code that doesn't
- bother indenting at all). We consider the column of the first
+ bother indenting at all).
+ For "else" clauses, we consider the column of the first
non-whitespace character on the guard line instead of the column
of the actual guard token itself because it is more sensible.
Consider:
@@ -438,14 +439,17 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo,
foo (2); // BODY
foo (3); // NEXT
- If we just used the column of the guard token, we would warn on
+ If we just used the column of the "else" token, we would warn on
the first example and not warn on the second. But we want the
exact opposite to happen: to not warn on the first example (which
is probably autogenerated) and to warn on the second (whose
indentation is misleading). Using the column of the first
non-whitespace character on the guard line makes that
happen. */
- if (guard_line_first_nws == body_vis_column)
+ unsigned int guard_column = (guard_tinfo.keyword == RID_ELSE
+ ? guard_line_first_nws
+ : guard_vis_column);
+ if (guard_column == body_vis_column)
return false;
/* We may have something like:
@@ -458,9 +462,9 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo,
foo (3); // NEXT
in which case the columns are not aligned but the code is not
- misleadingly indented. If the column of the body is less than
- that of the guard line then don't warn. */
- if (body_vis_column < guard_line_first_nws)
+ misleadingly indented. If the column of the body isn't indented
+ more than the guard line then don't warn. */
+ if (body_vis_column <= guard_line_first_nws)
return false;
/* Don't warn if there is multiline preprocessor logic between