This is the mail archive of the 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++ PATCH] Fix -Wlogical-not-parentheses (PR c++/62199)

On 08/20/2014 04:02 PM, Marek Polacek wrote:
On Wed, Aug 20, 2014 at 02:36:21PM -0400, Jason Merrill wrote:
Could we set current.lhs_type to TRUTH_NOT_EXPR when we see a ! rather than
track nots in two separate local variables?

Good point.  So like the following?

I was thinking to do away with parenthesized_not_lhs_warn as well, so instead of

  bool parenthesized_not_lhs_warn
    = cp_lexer_next_token_is (parser->lexer, CPP_NOT);

  /* Parse the first expression.  */
  current.lhs = cp_parser_cast_expression (parser, /*address_p=*/false,
                                           cast_p, decltype_p, pidk);
  current.lhs_type = ERROR_MARK;

we would set current.lhs_type to TRUTH_NOT_EXPR here if the first token is CPP_NOT, and

      /* Extract another operand.  It may be the RHS of this expression
         or the LHS of a new, higher priority expression.  */
      rhs = cp_parser_simple_cast_expression (parser);
      rhs_type = ERROR_MARK;

here we would do the same thing for rhs_type.

       cp_lexer_consume_token (parser->lexer);
+      if (cp_lexer_next_token_is (parser->lexer, CPP_NOT))
+	current.lhs_type = TRUTH_NOT_EXPR;
 	  current.lhs = rhs;
+	  parenthesized_not_lhs_warn = current.lhs_type == TRUTH_NOT_EXPR;
 	  current.lhs_type = rhs_type;

and then you don't need any changes in these places.

       if (warn_logical_not_paren
 	  && parenthesized_not_lhs_warn)

And here you check current.lhs_type.


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