From 38b0babd5a642cea8912524debc63edc67fda08b Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Sun, 2 May 2021 17:14:38 +0200 Subject: 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: Michael Schmidt --- cparser/Unblock.ml | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cparser') diff --git a/cparser/Unblock.ml b/cparser/Unblock.ml index d25f70c6..8530ae01 100644 --- a/cparser/Unblock.ml +++ b/cparser/Unblock.ml @@ -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 -- cgit