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.
This commit is contained in:
Stephen Heumann 2022-10-16 19:57:14 -05:00
parent a864954353
commit afe40c0f67
2 changed files with 5 additions and 1 deletions

View File

@ -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;

View File

@ -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';