Reimplement assignment as truth value.

The source of the assignment is used as the value to test, and the
assignment itself is inserted into the boolean expressions's block. This
fixes the inernal error for "if ((x = 0))".
This commit is contained in:
Bill Currie 2012-12-23 19:53:31 +09:00
parent a881fb5f5b
commit f6c4e06183
1 changed files with 11 additions and 0 deletions

View File

@ -1191,6 +1191,17 @@ convert_bool (expr_t *e, int block)
if (!e->paren && options.warnings.precedence)
warning (e, "suggest parentheses around assignment "
"used as truth value");
b = convert_bool (e->e.expr.e2, 1);
if (b->type == ex_error)
return b;
// insert the assignment into the bool's block
e->next = b->e.bool.e->e.block.head;
b->e.bool.e->e.block.head = e;
if (b->e.bool.e->e.block.tail == &b->e.bool.e->e.block.head) {
// shouldn't happen, but just in case
b->e.bool.e->e.block.tail = &e->next;
}
return b;
}
if (e->type == ex_uexpr && e->e.expr.op == '!') {