1: Sample code that reproduces the problem.
int f(void)
{
struct S x;
struct S { int v; };
return sizeof x;
}
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 and emits no diagnostic. A diagnostic is required.
N3886 6.7.1 paragraph 6 requires an object with no linkage and without function prototype scope to have complete type by the end of its declarator, or by the end of its init-declarator if initialised. At the end of x's declarator, struct S is incomplete. Completing it in a subsequent declaration does not make the earlier declaration valid.
Reference: N3886.
5: Additional checks.
A union completed after its object declaration is also silently accepted, as is the struct case when the subsequent code writes and reads the member. Defining the struct or union before the object declaration is valid and compiles without diagnostics. The earlier [bugs:#4096] concerns an initialiser for an incomplete object; these examples have no initialiser.
All invalid variants were accepted without diagnostics on Z80, MCS51, STM8, PDK14 and MOS65C02 in C99, C11, C23 and C2Y modes. GCC 13.3.0 with -std=c2x -pedantic-errors -fsyntax-only rejects them and accepts the valid cases. GCC 16.2 and Clang were not tested.