1: Sample code that reproduces the problem.
struct S { int size; char data[]; };
union U { struct S value; int other; };
struct T { union U value; };
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.
4: Observed and expected behaviour.
SDCC exits successfully and emits no diagnostic.
WG14 N3886,
6.7.3.2 paragraph 3, specifies the constraint violated by the sample.
A union may contain a structure with a flexible array member. That union, including any union recursively containing it, must not itself be a structure member or an array element. Both prohibited contexts are silently accepted, including an extra union nesting level. A union declaration alone is valid; fixed-size arrays make both containing contexts valid.
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 |
|---|---|---|
flex-fixed-control.c |
Valid | Accepted silently on all five targets |
flex-nested-union-array.c |
Diagnostic required | Accepted silently on all five targets |
flex-nested-union-member.c |
Diagnostic required | Accepted silently on all five targets |
flex-union-array.c |
Diagnostic required | Accepted silently on all five targets |
flex-union-control.c |
Valid | Accepted silently on all five targets |
flex-union-member.c |
Diagnostic required | Accepted silently on all five targets |
Related report: [bugs:#4094]. The earlier report tests an array whose element is the flexible-array structure itself; this report tests containment through a union, including recursive unions.
Diff:
Related
Bugs:
#4094