shithub: scc

Download patch

ref: b08f92985bfbf55d321c4942b3742823515c2ba0
parent: e4d7773b6ee603349d12c0367518d356070b1135
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Apr 18 05:29:21 EDT 2014

Convert expressions of ternary operator

In a ternary operator the two result expressions must be of the
same type, or in other case they must be converted to the same type.

--- a/expr.c
+++ b/expr.c
@@ -691,7 +691,7 @@
 static Node *
 ternary(void)
 {
-	register Node *cond, *ifyes, *ifno;
+	Node *cond, *ifyes, *ifno;
 
 	cond = or();
 	while (accept('?')) {
@@ -698,7 +698,7 @@
 		ifyes = promote(expr());
 		expect(':');
 		ifno = promote(ternary());
-		/* TODO: check the types of ifno and ifyes */
+		typeconv(&ifyes, &ifno);
 		cond = ternarycode(compare(ONE, cond, constcode(zero)),
 	                           ifyes, ifno);
 	}