scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit c9a7bedda831d58121897c43f3e92badb6852f3a
parent b08f92985bfbf55d321c4942b3742823515c2ba0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 18 Apr 2014 10:03:47 +0200

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.

Diffstat:
Mexpr.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/expr.c b/expr.c @@ -692,13 +692,17 @@ static Node * ternary(void) { Node *cond, *ifyes, *ifno; + Type *tp1, *tp2; cond = or(); while (accept('?')) { ifyes = promote(expr()); expect(':'); ifno = promote(ternary()); - typeconv(&ifyes, &ifno); + tp1 = UNQUAL(ifyes->type); + tp2 = UNQUAL(ifno->type); + if (tp1 != tp2) + typeconv(&ifyes, &ifno); cond = ternarycode(compare(ONE, cond, constcode(zero)), ifyes, ifno); }