From 94584b0f05fe35e8d22fe9d1690a0c3bc422e1e6 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 30 Nov 2022 17:57:21 -0600 Subject: [PATCH] Give error for arrays that are still 0 size after initialization. This prohibits empty initializers ({}) for arrays of unknown size, consistent with C23 requirements. Previous versions of C did not allow empty initializers at all, but ORCA/C historically did in some cases, so this patch still allows them for structs/unions/arrays of known size. --- Parser.pas | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Parser.pas b/Parser.pas index c00ce7e..9eb58f2 100644 --- a/Parser.pas +++ b/Parser.pas @@ -2595,9 +2595,15 @@ var done := true; until done or (token.kind = eofsy); if maxCount = 0 then begin {set the array size} - maxCount := (maxDisp - startingDisp + ktp^.size - 1) div ktp^.size; - tp^.elements := maxCount; - RecomputeSizes(variable^.itype); + if maxDisp <> startingDisp then begin + maxCount := (maxDisp - startingDisp + ktp^.size-1) div ktp^.size; + tp^.elements := maxCount; + RecomputeSizes(variable^.itype); + end {if} + else begin + Error(49); + errorFound := true; + end; {else} end; {if} if braces then begin disp := startingDisp + maxCount * ktp^.size;