warn about the dangers of (!foo & bar)

This commit is contained in:
Bill Currie 2001-06-28 15:20:31 +00:00
parent 443196e66b
commit 0271afbb10
3 changed files with 8 additions and 1 deletions

View file

@ -27,6 +27,7 @@ typedef struct expr_s {
expr_type type;
int line;
string_t file;
int paren;
union {
label_t label;
block_t block;

View file

@ -438,6 +438,12 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
if (e1->type >= ex_int && e2->type >= ex_int)
return binary_const (op, e1, e2);
if ((op == '&' || op == '|')
&& e1->type == ex_uexpr && e1->e.expr.op == '!' && !e1->paren) {
fprintf (stderr, "%s:%d: warning: ambiguous logic. Suggest explicit parentheses with expressions involving ! and &\n",
strings + e1->file, e1->line);
}
t1 = get_type (e1);
t2 = get_type (e2);
if (t1 == ev_void || t2 == ev_void) {

View file

@ -410,7 +410,7 @@ expr
$$->e.def = PR_GetDef (NULL, $1, pr_scope, false);
}
| const { $$ = $1; }
| '(' expr ')' { $$ = $2; }
| '(' expr ')' { $$ = $2; $$->paren = 1; }
;
arg_list