diff options
author | Marek Polacek <polacek@redhat.com> | 2016-08-25 12:48:34 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2016-08-25 12:48:34 +0000 |
commit | ebef225f4d824e45982955fe2a3cceb4f8cbae0e (patch) | |
tree | 64f9fab13affc9a9f00a3ad4510b0ea04da7f713 /gcc/c-family | |
parent | 30df8b9f1e45879851eca44923eb77b0099fa24e (diff) | |
download | gcc-ebef225f4d824e45982955fe2a3cceb4f8cbae0e.zip gcc-ebef225f4d824e45982955fe2a3cceb4f8cbae0e.tar.gz gcc-ebef225f4d824e45982955fe2a3cceb4f8cbae0e.tar.bz2 |
c-common.c (warn_logical_not_parentheses): Print fixit hints.
* c-common.c (warn_logical_not_parentheses): Print fixit hints.
* c-common.h (warn_logical_not_parentheses): Update declaration.
* c-typeck.c (parser_build_binary_op): Pass LHS to
warn_logical_not_parentheses.
* parser.c (cp_parser_binary_expression): Pass LHS to
warn_logical_not_parentheses.
* c-c++-common/Wlogical-not-parentheses-2.c: New test.
Co-Authored-By: David Malcolm <dmalcolm@redhat.com>
From-SVN: r239756
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 20 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 3 |
3 files changed, 24 insertions, 5 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index fe98090..f8a7425 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2016-08-25 Marek Polacek <polacek@redhat.com> + David Malcolm <dmalcolm@redhat.com> + + * c-common.c (warn_logical_not_parentheses): Print fixit hints. + * c-common.h (warn_logical_not_parentheses): Update declaration. + 2016-08-22 Marek Polacek <polacek@redhat.com> PR c++/77321 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 3feb910..001070d 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -1485,7 +1485,7 @@ warn_tautological_cmp (location_t loc, enum tree_code code, tree lhs, tree rhs) void warn_logical_not_parentheses (location_t location, enum tree_code code, - tree rhs) + tree lhs, tree rhs) { if (TREE_CODE_CLASS (code) != tcc_comparison || TREE_TYPE (rhs) == NULL_TREE @@ -1498,9 +1498,21 @@ warn_logical_not_parentheses (location_t location, enum tree_code code, && integer_zerop (rhs)) return; - warning_at (location, OPT_Wlogical_not_parentheses, - "logical not is only applied to the left hand side of " - "comparison"); + if (warning_at (location, OPT_Wlogical_not_parentheses, + "logical not is only applied to the left hand side of " + "comparison") + && EXPR_HAS_LOCATION (lhs)) + { + location_t lhs_loc = EXPR_LOCATION (lhs); + rich_location richloc (line_table, lhs_loc); + richloc.add_fixit_insert (lhs_loc, "("); + location_t finish = get_finish (lhs_loc); + location_t next_loc + = linemap_position_for_loc_and_offset (line_table, finish, 1); + richloc.add_fixit_insert (next_loc, ")"); + inform_at_rich_loc (&richloc, "add parentheses around left hand side " + "expression to silence this warning"); + } } /* Warn if EXP contains any computations whose results are not used. diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index bc22baa..42ce969 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -847,7 +847,8 @@ extern void overflow_warning (location_t, tree); extern bool warn_if_unused_value (const_tree, location_t); extern void warn_logical_operator (location_t, enum tree_code, tree, enum tree_code, tree, enum tree_code, tree); -extern void warn_logical_not_parentheses (location_t, enum tree_code, tree); +extern void warn_logical_not_parentheses (location_t, enum tree_code, tree, + tree); extern void warn_tautological_cmp (location_t, enum tree_code, tree, tree); extern void check_main_parameter_types (tree decl); extern bool c_determine_visibility (tree); |