diff options
author | Patrick Palka <ppalka@gcc.gnu.org> | 2015-09-22 23:06:31 +0000 |
---|---|---|
committer | Patrick Palka <ppalka@gcc.gnu.org> | 2015-09-22 23:06:31 +0000 |
commit | d53980585be4b73f995d29a2ebd79f9729ec5e20 (patch) | |
tree | e099691467a47f2147d2919e9f0fd19d7753e672 /gcc/c-family | |
parent | 6c98d4995ce54ff8bec88a5b40a654007e4eb1bd (diff) | |
download | gcc-d53980585be4b73f995d29a2ebd79f9729ec5e20.zip gcc-d53980585be4b73f995d29a2ebd79f9729ec5e20.tar.gz gcc-d53980585be4b73f995d29a2ebd79f9729ec5e20.tar.bz2 |
Fix -Wmisleading-indentation false-positive
gcc/c-family/ChangeLog:
* c-indentation.c (should_warn_for_misleading_indentation):
Float out and consolidate the calls to get_visual_column that
are passed guard_exploc as an argument. Compare
next_stmt_vis_column with guard_line_first_nws instead of with
body_line_first_nws.
gcc/testsuite/ChangeLog:
* c-c++-common/Wmisleading-indentation.c: Augment test.
From-SVN: r228027
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-family/c-indentation.c | 23 |
2 files changed, 16 insertions, 15 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 381cb92..e887735 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,11 @@ +2015-09-22 Patrick Palka <ppalka@gcc.gnu.org> + + * c-indentation.c (should_warn_for_misleading_indentation): + Float out and consolidate the calls to get_visual_column that + are passed guard_exploc as an argument. Compare + next_stmt_vis_column with guard_line_first_nws instead of with + body_line_first_nws. + 2015-09-22 Nathan Sidwell <nathan@codesourcery.com> * c.opt (Wmultiple-inheritance, Wvirtual-inheritance, Wtemplates, diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-indentation.c index dd35223..5316316 100644 --- a/gcc/c-family/c-indentation.c +++ b/gcc/c-family/c-indentation.c @@ -341,6 +341,8 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, unsigned int next_stmt_vis_column; unsigned int body_vis_column; unsigned int body_line_first_nws; + unsigned int guard_vis_column; + unsigned int guard_line_first_nws; /* If we can't determine it, don't issue a warning. This is sometimes the case for input files containing #line directives, and these are often for autogenerated sources (e.g. from .md files), where @@ -351,6 +353,11 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, &body_vis_column, &body_line_first_nws)) return false; + if (!get_visual_column (guard_exploc, + &guard_vis_column, + &guard_line_first_nws)) + return false; + if ((body_type != CPP_SEMICOLON && next_stmt_vis_column == body_vis_column) /* As a special case handle the case where the body is a semicolon @@ -365,7 +372,7 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, || (body_type == CPP_SEMICOLON && body_exploc.line > guard_exploc.line && body_line_first_nws != body_vis_column - && next_stmt_vis_column == body_line_first_nws)) + && next_stmt_vis_column > guard_line_first_nws)) { /* Don't warn if they are aligned on the same column as the guard itself (suggesting autogenerated code that doesn't @@ -395,13 +402,6 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, indentation is misleading). Using the column of the first non-whitespace character on the guard line makes that happen. */ - unsigned int guard_vis_column; - unsigned int guard_line_first_nws; - if (!get_visual_column (guard_exploc, - &guard_vis_column, - &guard_line_first_nws)) - return false; - if (guard_line_first_nws == body_vis_column) return false; @@ -462,13 +462,6 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, { if (body_exploc.line == guard_exploc.line) { - unsigned int guard_vis_column; - unsigned int guard_line_first_nws; - if (!get_visual_column (guard_exploc, - &guard_vis_column, - &guard_line_first_nws)) - return false; - if (next_stmt_vis_column > guard_line_first_nws || (next_tok_type == CPP_OPEN_BRACE && next_stmt_vis_column == guard_vis_column)) |