Jean-Pierre Vial wrote:
Le Lundi 21 Avril 2003 03:24, Frank Heckenbach a écrit :
GCC supports `-Wparentheses' (warn about some constructs where parentheses are suggested for clarification, although not strictly syntactically necessary). The corresponding code is also there for GPC. I'm going to activate it now. The questions are:
Which constructs to warn about? So far, I've come up with the following ones:
`and' in an operand of `or', as in `a or b and c' which is equivalent to `a or (b and c)', but may confuse the reader. (Same for `and_then' instead of `and' etc., of course.)
logical operations (`and', `or', `not', etc.) in an operand of a relational operator (`=', etc., `in'). This would catch cases like the dreaded `if not a = b'.
What should be the default? I suggest off by default and on with `-Wall' (same as in GCC).
if the list is as short as the one you propose, the default can be on, because in these cases, even if parentheses are actually unnecessary, they greatly improve legibility, and so make maintenance very much simpler and safer. if the list is longer, and includes less obvious cases, it is better that the default be off
1. precedence of operators.
It is well defined that a or b and c is equal to a or (b and c) , as a + b * c equal to a + (b * c). A warning here is annoying. If at all, it should be a separate option, off by default and not included in -Wall.
2. logical operations in an operand of a relational operator
OK, this can be confusing, a warning is useful (off by default and on with -Wall).
Regards,
Adriaan van Os