aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-04-14 18:40:42 +0200
committerlemon <lsof@mailbox.org>2026-04-14 18:40:42 +0200
commitcbf1018b21ea2a060a3825fbdb1453800b5b7320 (patch)
tree1a0f753f16fa93c8c0fbc62f4c8c83c7f622d4ab /src
parent98222b7c0506b0a9833230177b939f8c25046b31 (diff)
c: make type of conditional expr with pointers match non void pointer
Here's what the C standard[1] says about the conditional operator: ``` if one operand is a null pointer constant, the result has the type of the other operand; otherwise, one operand is a pointer to void or a qualified version of void, in which case the result type is a pointer to an appropriately qualified version of void. `` But actually, some codebases rely on things like 'x ? &foo.memb : NULL' to have the type of `&foo.memb`, and not `void *`... [1]: ISO/IEC 9899:TC3 ยง6.5.15
Diffstat (limited to 'src')
-rw-r--r--src/c.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/c.c b/src/c.c
index 2d51bd2..c6df58f 100644
--- a/src/c.c
+++ b/src/c.c
@@ -540,7 +540,7 @@ condtype(const Expr *a, const Expr *b)
if (t1.t == TYPTR && t2.t == TYPTR) {
s1 = typechild(t1), s2 = typechild(t2);
if (s1.bits == s2.bits || s2.t == TYVOID || s1.t == TYVOID) {
- return mkptrtype(s1.t == TYVOID ? s1 : s2, (t1.flag | t2.flag) & TFCHLDQUAL);
+ return mkptrtype(s1.t == TYVOID ? s2 : s1, (t1.flag | t2.flag) & TFCHLDQUAL);
}
}
return mktype(0);