From afe40c0f679512c4be3b33c2a507720c874658a4 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 16 Oct 2022 19:57:14 -0500 Subject: [PATCH] Prevent spurious errors about structs containing function pointers. If a struct contained a function pointer with a prototyped parameter list, processing the parameters could reset the declaredTagOrEnumConst flag, potentially leading to a spurious error, as in this example: struct S { int (*f)(int); }; This also gives a better error for structs declared as containing functions. --- Parser.pas | 4 ++++ Scanner.pas | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Parser.pas b/Parser.pas index cbf93f1..f1a5a39 100644 --- a/Parser.pas +++ b/Parser.pas @@ -1330,6 +1330,7 @@ var lLastParameter: identPtr; {next parameter to process} luseGlobalPool: boolean; {local copy of useGlobalPool} lSuppressMacroExpansions: boolean;{local copy of suppressMacroExpansions} + ldeclaredTagOrEnumConst: boolean; {local copy of declaredTagOrEnumConst} begin {StackDeclarations} lastWasIdentifier := false; {used to see if the declaration is a fn} @@ -1484,9 +1485,12 @@ var prototyped := true; {it is prototyped} repeat {collect the declarations} if token.kind in declarationSpecifiersElement then begin + ldeclaredTagOrEnumConst := declaredTagOrEnumConst; lLastParameter := lastParameter; DoDeclaration(true); lastParameter := lLastParameter; + declaredTagOrEnumConst := + ldeclaredTagOrEnumConst or declaredTagOrEnumConst; if protoType <> nil then begin wp := pointer(Malloc(sizeof(parameterRecord))); wp^.next := parameterList; diff --git a/Scanner.pas b/Scanner.pas index a8eb77a..e26e1b9 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -693,7 +693,7 @@ if list or (numErr <> 0) then begin 114: msg := @'a function call was made to a non-function'; 115: msg := @'illegal bit field declaration'; 116: msg := @'missing field name'; - 117: msg := @'field cannot have incomplete type'; + 117: msg := @'field cannot have incomplete or function type'; 118: msg := @'flexible array must be last member of structure'; 119: msg := @'inline specifier is only allowed on functions'; 120: msg := @'non-static inline functions are not supported';