Menu ▾ ▴

#4263 Braced anonymous union initialiser incorrectly reports a missing member

open
None
other
5
2026-11-19
2026-11-19
No

1: Sample code that reproduces the problem.

Save as aggregate.c.

struct S { union { struct { int b; } a; int c; }; };
#ifdef LOCAL
void test(void)
{
  struct S object = {{.a = {.b = 1}}};
  (void)object;
}
#else
struct S object = {{.a = {.b = 1}}};
#endif

2: Exact command used to run SDCC on this sample code.

sdcc -mz80 --std-c11 -S aggregate.c -o aggregate.asm

3: SDCC version tested.

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/huc6280/f8/f8l TD- 4.6.4 #17200 (Linux)
published under GNU General Public License (GPL)

Unmodified official snapshot, retested on Linux x86_64 on 18 November 2026.

4: Observed and expected behaviour.

aggregate.c:9: error 26: 'a' not a structure/union member

The compiler exits with status 1. The inner braces initialise the anonymous union; .a selects its structure member and .b selects a member of that structure. The program should compile successfully with object.a.b == 1.

5: Additional checks.

The automatic-storage variant is also rejected when -DLOCAL is added to the command above. GCC accepts both variants with -std=c11 -pedantic-errors -fsyntax-only. The rejections were also reproduced on STM8, MCS51 default and PDK14 with r17200.

Compiler Explorer uses the same source and SDCC trunk with -mz80 --std-c11. The CE build tested was SDCC 4.6.4 #17204 (Linux), distinct from the local r17200 retest.

Possibly related to [bugs:#3584] (anonymous-member initialisation semantics) and [bugs:#3393] (anonymous-union initialisation). These exact reproducers were not found in those reports.

Related

Bugs: #2948
Bugs: #3393
Bugs: #3584
Wiki: SDCC 4.7.0 Release

Discussion

  • Christopher Bazley

     
  • Christopher Bazley

    The candidate patch attached to [bugs:#2948] includes a fix and regression test for this bug. Please review the patch there.

     

    Related

    Bugs: #2948


Log in to post a comment.