This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: Jason Merrill <jason at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Wed, 4 Jun 2014 23:02:10 +0200
- Subject: Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)
- Authentication-results: sourceware.org; auth=none
- References: <20140602065052 dot GE31671 at redhat dot com> <538C8558 dot 7010404 at redhat dot com> <20140602151732 dot GA11694 at redhat dot com> <538C9FD2 dot 7050404 at redhat dot com> <20140602162300 dot GD11694 at redhat dot com> <538CA6E4 dot 2040401 at redhat dot com> <20140602163606 dot GO10386 at tucnak dot redhat dot com> <20140602170457 dot GA27647 at redhat dot com> <538CB97D dot 8040904 at redhat dot com> <20140604205643 dot GJ29196 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Jun 04, 2014 at 10:56:43PM +0200, Marek Polacek wrote:
> +/* Warn about logical not used on the left hand side operand of a comparison.
> + This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
> + Do not warn if the LHS or RHS is of a boolean or a vector type. */
> +
> +void
> +warn_logical_not_parentheses (location_t location, enum tree_code code,
> + tree lhs, tree rhs)
> +{
> + if (TREE_TYPE (lhs) == NULL_TREE
> + || TREE_TYPE (rhs) == NULL_TREE)
> + ;
> + else if (TREE_CODE_CLASS (code) != tcc_comparison
Shouldn't this test be done first? I mean, if type is NULL on lhs or rhs,
you'll warn even when code is not comparison...
> + || TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE
> + || TREE_CODE (TREE_TYPE (rhs)) == BOOLEAN_TYPE
> + || VECTOR_TYPE_P (TREE_TYPE (lhs))
> + || VECTOR_TYPE_P (TREE_TYPE (rhs)))
> + return;
> +
> + warning_at (location, OPT_Wlogical_not_parentheses,
> + "logical not is only applied to the left hand side of "
> + "comparison");
> +}
>
Jakub