1: Sample code that reproduces the problem.
void *f(int c, int n, void *p)
{
return c ? (int (*)[n])p : 0;
}
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 #17068 (Linux), tested 23 October 2026.
4: Observed and expected behaviour.
SDCC exits successfully without emitting a diagnostic.
N3886 6.5.16 paragraph 5 requires a diagnostic when one result operand is a pointer to a variably modified type and the other is a null pointer constant or has nullptr_t type, if that pointer type depends on an array length expression left unevaluated when its branch is not selected. Here the array length expression n belongs to the cast in the second operand and is not evaluated when c is false. This violates the constraint even though n was declared as a parameter.
The same paragraph also prohibits forming a composite type from an array of unknown length and an array whose length expression remains unevaluated when its branch is not selected. Thus return c ? (int (*)[n])p : (int (*)[])q;, with p and q of type void *, also requires a diagnostic. N3886 6.5.16 paragraph 12 gives corresponding invalid examples.
Reference: N3886.
5: Additional checks.
Three invalid variants compile silently in C2Y mode on all five targets (15 checks): an integer null pointer constant in the other branch, nullptr in the other branch, and an unknown-length array pointer in the other branch.
The corresponding valid cases declare int (*a)[n] = p; before the conditional and then use c ? a : 0 or c ? a : b, where b points to an unknown-length array. Both compile silently on all five targets. Their length expression has already been evaluated, as in N3886 paragraph 13.
This report is specifically about the N3886 C2Y constraints. No diagnostic obligation is claimed for these examples in earlier C editions. GCC 13.3.0 was used only for the valid examples; it is not a reference implementation of the new C2Y constraints. The candidate valdiag file selects C2Y once under SDCC and skips these cases for host compilers whose support has not been established. It currently fails 3 of 5 cases on each target; both valid cases pass.
Targets tested: Z80, MCS51, STM8, PDK14 and MOS65C02. These are compile-time checks, not runtime tests. GCC 16.2 and Clang were not tested.
Diff: