Menu ▾ ▴

#4094 Structure with a flexible array member is accepted as an array element type

closed-fixed
None
Front-end
5
2026-10-07
2026-09-28
No

1: Sample code that reproduces the problem.

struct flexible {
  int count;
  int data[];
};

struct flexible array[2]; /* ERROR */

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

./bin/sdcc -c bug.c

3: SDCC version tested

Git f68fca8a4368ece9fe93b21f2e0341282b104359, SDCC 4.6.3 #0 (Linux).

Affected in valdiag testing on mcs51, mcs51-large, mcs51-stack-auto, ds390, z80, z180, r2k, r4k, sm83, tlcs90, hc08, s08, mos6502, huc6280, stm8, f8, pdk13, pdk14, and pdk15.

4: Copy of the error message or incorrect output, or a clear description of the observed versus expected behavior.

N3886 6.7.3.2p3 says that a structure containing a flexible array member shall not be a member of a structure or an element of an array. According to the ISO C standard, all constraint violations must be diagnosed. SDCC accepts the array declaration without a diagnostic.

Clang 18.1.3 and GCC 13.3.0 diagnose the constraint violation. TCC 0.9.28rc (mob 9db1105, 2026-09-26) accepts it without a diagnostic and therefore has the same bug.

Related

Bugs: #4197

Discussion

  • Christopher Bazley

    Attaching a candidate patch to fix this bug.

    This is one of eight independent patches against SDCC commit
    c8cee3a5b4656a3d7ef97ef6078c38a016a02cfb (2026-09-28).
    The patches were also applied together to the baseline commit and built with the PIC14 and PIC16 ports disabled. The full device library build completed successfully. Focused valdiag testing of the eight new files passed on all 19 valdiag targets: 27 checks per target, zero failures.

    make -C support/regression -j2 test-ucz80:

    0 failures, 36745 tests, 6409 test cases
    
     

    Last edit: Christopher Bazley 2026-09-29
  • Philipp Klaus Krause

    • status: open --> closed-fixed
    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    Thanks. Fixed via your patch in [r16977], with an added #pragma disable_warning for a preexisting test where the new warning triggers.

     

    Related

    Commit: [r16977]


Log in to post a comment.