Handle function-typed parameters whose own params start with attributes.

The parsing logic for unnamed parameters sometimes needs to look ahead an extra token to account for this.

Here are examples of function declarations affected by this logic, as well as equivalent and compatible ways of declaring the same functions:

int f(int([[]] int));
int f(int (*)(int));

int g(int([]));
int g(int*);
This commit is contained in:
Stephen Heumann
2025-06-08 22:55:10 -05:00
parent 5a4fef4175
commit 19804e013b
+18
View File
@@ -1518,6 +1518,23 @@ var
unnamedParm := true;
end; {MakeUnnamedParameter}
function PeekToken: tokenEnum;
{ peek at next token and get its kind }
var
tToken: tokenType; {temporary copy of current token}
begin {PeekToken}
tToken := token;
NextToken;
PeekToken := token.kind;
PutBackToken(token, false, true);
token := tToken;
end; {PeekToken}
begin {StackDeclarations}
lastWasIdentifier := false; {used to see if the declaration is a fn}
cpList := nil;
@@ -1588,6 +1605,7 @@ var
NextToken;
if doingPrototypes
and (token.kind in prototypeParameterDeclarationStart)
and ((token.kind <> lbrackch) or (PeekToken = lbrackch))
then begin { unnamed param declared with fn type }
PutBackToken(token, false, true);
token.kind := lparench;