union U
{
char a[4];
char *p;
};
_Static_assert (_Generic (((union U *)0)->a,
char *: 1,
default: 0),
"union array member has its declared element type");
_Static_assert (_Generic (((union U *)0)->p,
char *: 1,
default: 0),
"union membership does not qualify the pointer target");
A comparison of SDCC 4.6.0 with the behaviour of three other C compilers is here: https://godbolt.org/z/9xMorMWM5
sdcc --std-c11 -c union-volatile.c
Reproduced with the following version:
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/r4k/r5k/r6k/sm83/tlcs90/ez80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/f8/f8l TD- 4.5.24 #16456 (Mac OS X ppc)
Copy of the error message or incorrect output:
union-volatile.c:9: warning 215: static assertion failed: "union array member has its declared element type"
union-volatile.c:14: warning 215: static assertion failed: "union membership does not qualify the pointer target"
SDCC internally marks every member of a union as volatile. This appears to be intended to prevent unsafe optimization of accesses which might alias another member of the union. However, the flag used for this purpose is also the flag representing the C volatile type qualifier. Consequently, union membership changes the language-level type of a member.
This is observable through _Generic, as in the example above, and can also cause incorrect pointer-qualifier diagnostics. The behaviour needed to prevent unsafe optimisation of union accesses should therefore be represented separately from the C type qualifier.
Sorry, this duplicates bug [#4072].
Related
Bugs: #4072
Last edit: Maarten Brock 2026-09-12