aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-indentation.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-06-02 18:45:50 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-06-02 18:45:50 +0000
commit6ac481556e7ce457d72eb44b9a07db3fae63ed8a (patch)
tree978f85d03f17cc62ee6d5c54d34589c0e09a0def /gcc/c-family/c-indentation.c
parent773ce42e90609a47d648eed62afc05a2f309f300 (diff)
downloadgcc-6ac481556e7ce457d72eb44b9a07db3fae63ed8a.zip
gcc-6ac481556e7ce457d72eb44b9a07db3fae63ed8a.tar.gz
gcc-6ac481556e7ce457d72eb44b9a07db3fae63ed8a.tar.bz2
PR c/66220: Fix false positive from -Wmisleading-indentation
gcc/c-family/ChangeLog: PR c/66220: * c-indentation.c (should_warn_for_misleading_indentation): Use expand_location rather than expand_location_to_spelling_point. Don't warn if the guarding statement is more indented than the next/body stmts. gcc/testsuite/ChangeLog: PR c/66220: * c-c++-common/Wmisleading-indentation.c (fn_35): New. (fn_36): New. From-SVN: r224041
Diffstat (limited to 'gcc/c-family/c-indentation.c')
-rw-r--r--gcc/c-family/c-indentation.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-indentation.c
index 9aeebae..1e3a6d8 100644
--- a/gcc/c-family/c-indentation.c
+++ b/gcc/c-family/c-indentation.c
@@ -230,10 +230,8 @@ should_warn_for_misleading_indentation (location_t guard_loc,
if (next_tok_type == CPP_SEMICOLON)
return false;
- expanded_location body_exploc
- = expand_location_to_spelling_point (body_loc);
- expanded_location next_stmt_exploc
- = expand_location_to_spelling_point (next_stmt_loc);
+ expanded_location body_exploc = expand_location (body_loc);
+ expanded_location next_stmt_exploc = expand_location (next_stmt_loc);
/* They must be in the same file. */
if (next_stmt_exploc.file != body_exploc.file)
@@ -257,8 +255,7 @@ should_warn_for_misleading_indentation (location_t guard_loc,
^ DON'T WARN HERE. */
if (next_stmt_exploc.line == body_exploc.line)
{
- expanded_location guard_exploc
- = expand_location_to_spelling_point (guard_loc);
+ expanded_location guard_exploc = expand_location (guard_loc);
if (guard_exploc.file != body_exploc.file)
return true;
if (guard_exploc.line < body_exploc.line)
@@ -299,6 +296,15 @@ should_warn_for_misleading_indentation (location_t guard_loc,
#endif
bar ();
^ DON'T WARN HERE
+
+ if (flag) {
+ foo ();
+ } else
+ {
+ bar ();
+ }
+ baz ();
+ ^ DON'T WARN HERE
*/
if (next_stmt_exploc.line > body_exploc.line)
{
@@ -319,14 +325,18 @@ should_warn_for_misleading_indentation (location_t guard_loc,
/* Don't warn if they aren't aligned on the same column
as the guard itself (suggesting autogenerated code that
doesn't bother indenting at all). */
- expanded_location guard_exploc
- = expand_location_to_spelling_point (guard_loc);
+ expanded_location guard_exploc = expand_location (guard_loc);
unsigned int guard_vis_column;
if (!get_visual_column (guard_exploc, &guard_vis_column))
return false;
if (guard_vis_column == body_vis_column)
return false;
+ /* PR 66220: Don't warn if the guarding statement is more
+ indented than the next/body stmts. */
+ if (guard_vis_column > body_vis_column)
+ return false;
+
/* Don't warn if there is multiline preprocessor logic between
the two statements. */
if (detect_preprocessor_logic (body_exploc, next_stmt_exploc))