Menu ▾ ▴

#4216 Variable-length array compound literals are silently accepted

open
nobody
None
Front-end
5
2026-10-24
2026-10-24
No

1: Sample code that reproduces the problem.

void f(int n)
{
  (int[n]){0};
}

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 #17068 (Linux), tested 23 October 2026.

4: Observed and expected behaviour.

SDCC exits successfully and emits no diagnostic.

N3886 6.5.3.6 paragraph 2 explicitly excludes a variable length array type from the type name of a compound literal. The parameter n is not an integer constant expression, so the array type is variable length. A diagnostic is required even when the compound-literal expression is discarded.

Reference: N3886.

5: Additional checks.

The nonempty example is silently accepted on Z80, MCS51, STM8, PDK14 and MOS65C02 in C99/C11/C23/C2Y: 20 checks. (int[n]){} is also accepted silently on all five targets in C2Y mode; the empty initialiser removes the separate restriction against nonempty VLA initialisation. A fixed-bound (int[2]){0} compiles silently. This report concerns the missing diagnostic for the prohibited compound literal; no runtime VLA implementation claim is made.

GCC 13.3.0 with -std=c2x -pedantic-errors -fsyntax-only rejects the invalid cases. GCC 16.2 and Clang were not tested. Source files, exact commands and output are in the evidence package. Candidate valdiag cases fail on r17068 until a diagnostic is added. These are compile-time diagnostic checks, not runtime tests.

Discussion


Log in to post a comment.