This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]