diff options
| author | 2026-04-14 18:40:42 +0200 | |
|---|---|---|
| committer | 2026-04-14 18:40:42 +0200 | |
| commit | cbf1018b21ea2a060a3825fbdb1453800b5b7320 (patch) | |
| tree | 1a0f753f16fa93c8c0fbc62f4c8c83c7f622d4ab | |
| parent | 98222b7c0506b0a9833230177b939f8c25046b31 (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
| -rw-r--r-- | src/c.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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); |