From 21efdd809bbc9626f63f8886c69b1a86cd4223fc Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Sun, 10 Jan 2016 16:39:39 +0000 Subject: [PATCH] Fix -Wmisleading indentation false-positive for do-while statement gcc/c-family/ChangeLog: PR c++/69029 * c-indentation.c (should_warn_for_misleading_indentation): Don't warn about do-while statements. gcc/testsuite/ChangeLog: PR c++/69029 * c-c++-common/Wisleading-indentation.c: Augment test. From-SVN: r232202 --- gcc/c-family/ChangeLog | 7 ++++++- gcc/c-family/c-indentation.c | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/Wmisleading-indentation.c | 2 ++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index a2743d8f8d94..d8282d9de470 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,4 +1,9 @@ -gcc/c-family/ChangeLog: +2016-01-10 Patrick Palka + + PR c++/69029 + * c-indentation.c (should_warn_for_misleading_indentation): + Don't warn about do-while statements. + 2016-01-07 Martin Sebor PR c/68966 diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-indentation.c index 3c09336d15ab..cd9637dc3fe0 100644 --- a/gcc/c-family/c-indentation.c +++ b/gcc/c-family/c-indentation.c @@ -202,6 +202,12 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, if (line_table->seen_line_directive) return false; + /* We can't usefully warn about do-while statements since the bodies of these + statements are always explicitly delimited at both ends, so control flow is + quite obvious. */ + if (guard_tinfo.keyword == RID_DO) + return false; + /* If the token following the body is a close brace or an "else" then while indentation may be sloppy, there is not much ambiguity about control flow, e.g. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f233bb923efb..615a527e1ce3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-01-10 Patrick Palka + + PR c++/69029 + * c-c++-common/Wisleading-indentation.c: Augment test. + 2016-01-10 Thomas Koenig PR fortran/69154 diff --git a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c index 491291c171cc..25db8fe8412f 100644 --- a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c +++ b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c @@ -890,6 +890,8 @@ fn_39 (void) i < 10; i++); foo (i); + + do foo (0); while (flagA); } /* We shouldn't complain about the following function. */