From 8cf560c502542af972eabd201a5b7bf05c891078 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 22 Nov 2025 19:10:40 +0100 Subject: c: fix precedence of conditional expression rhs --- c/c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c/c.c b/c/c.c index b6ca90e..05308e1 100644 --- a/c/c.c +++ b/c/c.c @@ -1080,7 +1080,7 @@ Unary: assert(ty.t); ex = mkexpr(ek, span, ty, .sub = exprdup2(cm, &ex, &rhs)); } else { - /* ex ? tmp : rhs */ + /* logical-OR-expression ? expression : conditional-expression */ struct expr *sub; span.sl = tk.span.sl; span.ex = ex.span.ex; @@ -1089,7 +1089,7 @@ Unary: tmp = commaexpr(cm); joinspan(&tk.span.ex, tmp.span.ex); expect(cm, ':', NULL); - rhs = expr(cm); + rhs = exprparse(cm, opprec, NULL, 0); if (!joinspan(&span.ex, tk.span.ex) || !joinspan(&span.ex, tmp.span.ex) || !joinspan(&span.ex, rhs.span.ex)) span.ex = tk.span.ex; -- cgit v1.2.3