From 742938c911864563a8b04b95cbcf53d8f12a4ef9 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 5 Jun 2014 06:20:05 +0000 Subject: re PR c/49706 (No warning for (!x > 1) which is always false) PR c/49706 * doc/invoke.texi: Document -Wlogical-not-parentheses. c-family/ * c-common.c (warn_logical_not_parentheses): New function. * c-common.h (warn_logical_not_parentheses): Declare. * c.opt (Wlogical-not-parentheses): New option. c/ * c-typeck.c (parser_build_binary_op): Warn when logical not is used on the left hand side operand of a comparison. cp/ * parser.c (cp_parser_binary_expression): Warn when logical not is used on the left hand side operand of a comparison. testsuite/ * c-c++-common/pr49706.c: New test. From-SVN: r211255 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-typeck.c | 4 ++++ 2 files changed, 10 insertions(+) (limited to 'gcc/c') diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 7bd3ce3..732c9c1 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,11 @@ 2014-06-05 Marek Polacek + PR c/49706 + * c-typeck.c (parser_build_binary_op): Warn when logical not is used + on the left hand side operand of a comparison. + +2014-06-05 Marek Polacek + PR c/48062 * c-decl.c (warn_if_shadowing): Call inform instead of warning_at. Print note only if the warning was printed. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index a98ce07..e0d3fde 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -3401,6 +3401,10 @@ parser_build_binary_op (location_t location, enum tree_code code, warn_logical_operator (location, code, TREE_TYPE (result.value), code1, arg1.value, code2, arg2.value); + if (warn_logical_not_paren + && code1 == TRUTH_NOT_EXPR) + warn_logical_not_parentheses (location, code, arg1.value, arg2.value); + /* Warn about comparisons against string literals, with the exception of testing for equality or inequality of a string literal with NULL. */ if (code == EQ_EXPR || code == NE_EXPR) -- cgit v1.1