1: Sample code that reproduces the problem.
int f(int *p, char *q) { return p == q; }
2: Exact command used to run SDCC on this sample code.
sdcc -mz80 --std=c2y --nostdinc -S bug.c -o bug.asm
3: SDCC version tested.
SDCC 4.6.4 #17064 (Linux), tested 21 October 2026. No candidate patch was applied.
4: Observed and expected behaviour.
SDCC exits successfully and emits no diagnostic for the sample.
WG14 N3886,
6.5.9 paragraph 2 and 6.5.10 paragraph 2, specifies the constraints violated by these examples.
int and char are incompatible types, so comparisons of these pointer types
require a diagnostic for ==, != and <. The special equality permission
involving void * does not apply to int * versus char *. Relational operators
require pointers to compatible object types; two function pointers therefore
cannot be ordered with <. Compatible object-pointer ordering, equality after
adding const, function-pointer equality and object-pointer/void-pointer
equality are valid cases. The valid ordering example checks translation
constraints; it makes no claim that arbitrary runtime arguments permit a
defined ordering.
5: Additional checks.
The sample is silently accepted on Z80, MCS51 default, STM8 default, PDK14 and MOS65C02 in C2Y mode. These are translation and diagnostic checks; no runtime result is claimed.
Compiler Explorer: SDCC 4.6.0, SDCC trunk and GCC 16.2. All three panes use the sample above. The saved source, compiler selections and options were round-trip verified on 21 October 2026. Both SDCC panes use -mz80 --std=c2y; GCC uses -std=c2y -pedantic-errors -fsyntax-only. The public trunk build is r17013, distinct from the local r17064 retest.
| CE compiler | Observed result |
|---|---|
| SDCC 4.6.0 | Accepted silently |
| SDCC trunk r17013 | Accepted silently |
| GCC 16.2 | Rejected with diagnostics |
| Case | Expected | Current SDCC results |
|---|---|---|
compatible-order-control.c |
Valid | Accepted silently on all five targets |
function-pointer-control.c |
Valid | Accepted silently on all five targets |
function-pointer-order.c |
Diagnostic required | Accepted silently on all five targets |
pointer-equal.c |
Diagnostic required | Accepted silently on all five targets |
pointer-order.c |
Diagnostic required | Accepted silently on all five targets |
pointer-unequal.c |
Diagnostic required | Accepted silently on all five targets |
qualified-pointer-control.c |
Valid | Accepted silently on all five targets |
void-pointer-control.c |
Valid | Accepted silently on all five targets |
Related report: [bugs:#3836]. That report concerns excessive diagnostics for address-space comparisons; this report concerns missing diagnostics for incompatible ordinary pointed-to types.
IMO, this should be a warning.
Yes. If it has never provoked an error before then it seems likely that existing programs violate the constraint. I implemented the diagnostic message as a warning in the attached patch. Please take a look when you have time, @spth.
The patch looks good, but I didn't check if the new warnings trigger in any existing regression tests; if they do we probably want
#pragma disable_warningin them.Yes, I needed to add that
pragmain support/regression/tests/bug-2710.c. Thanks for the review and reminder.Diff:
Related
Bugs: #3836
Fixed by [r17079]
Related
Commit: [r17079]