Menu ▾ ▴

#4188 Array and member designators on scalar initialisers go undiagnosed

open
nobody
None
Front-end
5
12 hours ago
2026-10-22
No

1: Sample code that reproduces the problem.

int object = {[0]=1};

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.

WG14 N3886,
6.7.11 paragraphs 10 and 11, specifies the relevant constraints.

An array designator requires the current object to have array type; a member
designator requires structure or union type. The current object is int in
these cases. SDCC accepts both forms, including a nonzero index and a block-
scope member designator, without a diagnostic. A plain braced scalar
initialiser, a real array designator and a real structure-member designator
are valid cases.

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
array-designator-control.c Valid Accepted silently on all five targets
member-designator-control.c Valid Accepted silently on all five targets
scalar-array-designator.c Diagnostic required Accepted silently on all five targets
scalar-braced-control.c Valid Accepted silently on all five targets
scalar-local-designator.c Diagnostic required Accepted silently on all five targets
scalar-member-designator.c Diagnostic required Accepted silently on all five targets
scalar-nonzero-designator.c Diagnostic required Accepted silently on all five targets

Related

Wiki: SDCC 4.7.0 Release

Discussion

  • Christopher Bazley

    • Category: other --> Front-end
     
  • Christopher Bazley

    Adding a candidate fix authored by Codex.

     
    • Philipp Klaus Krause

      Looks ok to me.

       

Log in to post a comment.