From f6c4e06183cfa559fb4ef07740b05587114c9fda Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 23 Dec 2012 19:53:31 +0900 Subject: [PATCH] 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))". --- tools/qfcc/source/expr.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 569d78901..c5f64bd19 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -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 == '!') {