From b89e243c47281dba7891d0299189d00d22e6b552 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 2 Oct 2023 09:04:31 +0900 Subject: [PATCH] [qfcc] Improve handling of different types in ?: --- tools/qfcc/source/expr.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 51a0a278c..b7faa1353 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2484,7 +2484,20 @@ conditional_expr (const expr_t *cond, const expr_t *e1, const expr_t *e2) backpatch (c->boolean.true_list, tlabel); backpatch (c->boolean.false_list, flabel); - block->block.result = (type1 == type2) ? new_temp_def_expr (type1) : 0; + if (!type_same (type1, type2)) { + if (!type_assignable (type1, type2) + && !type_assignable (type2, type1)) { + type1 = 0; + } + if (!type_assignable (type1, type2)) { + type1 = type2; + } + if (type_promotes (type2, type1)) { + type1 = type2; + } + } + + block->block.result = type1 ? new_temp_def_expr (type1) : 0; append_expr (block, c); append_expr ((expr_t *) c->boolean.e, flabel);//FIXME cast if (block->block.result)