Commit 38b0babd authored by Xavier Leroy's avatar Xavier Leroy
Browse files

Fix spurious error on initialization of struct with flexible array member

The following is correct but was causing a "wrong type for array initializer"
fatal error.

struct s { int n; int d[]; };
void f(void) { struct s x = {0}; }
Co-authored-by: default avatarMichael Schmidt <>
parent 2c47585b
......@@ -31,6 +31,9 @@ let rec local_initializer env path init k =
let (ty_elt, sz) =
match unroll env path.etyp with
| TArray(ty_elt, Some sz, _) -> (ty_elt, sz)
(* We accept empty array initializer for flexible array members, which
has size zero *)
| TArray(ty_elt, None, _) when il = [] -> (ty_elt, 0L)
| _ -> Diagnostics.fatal_error Diagnostics.no_loc "wrong type for array initializer" in
let rec array_init pos il =
if pos >= sz then k else begin
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment