From 237af41e909e46154156d95a66629314f3ad0915 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 24 Mar 2018 21:20:32 -0500 Subject: [PATCH] Fix issue where a label with the same name as a typedef name was parsed as the beginning of a declaration. This would lead to errors in programs like the following: int main(void) { typedef int x; x: ; } Even before support for mixed statements and declarations was introduced, this error could happen if the labeled statement was the first statement after the declarations in a block (as in the above example). Adding that support also allowed this error to happen with later statements in a block. The C4.2.4.1.CC test case was affected by this. --- Parser.pas | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Parser.pas b/Parser.pas index 09ff5b8..2fea0fe 100644 --- a/Parser.pas +++ b/Parser.pas @@ -3677,11 +3677,19 @@ procedure DoStatement; { process a statement from a function } +var + lToken: tokenType; {temporary copy of old token} + nToken: tokenType; {new token} + hasStatementNext: boolean; {is a stmt next within a compound stmt?} + lPrintMacroExpansions: boolean; {local copy of printMacroExpansions} + begin {DoStatement} case statementList^.kind of compoundSt: begin + hasStatementNext := true; if token.kind = rbracech then begin + hasStatementNext := false; EndCompoundStatement; end {if} else if (statementList^.doingDeclaration or allowMixedDeclarations) @@ -3690,9 +3698,27 @@ case statementList^.kind of floatsy,doublesy,compsy,extendedsy,enumsy, structsy,unionsy,typedef,voidsy,volatilesy, constsy]) - then - DoDeclaration(false) - else begin + then begin + hasStatementNext := false; + if token.kind <> typedef then + DoDeclaration(false) + else begin + lToken := token; + lPrintMacroExpansions := printMacroExpansions; {inhibit token echo} + printMacroExpansions := false; + NextToken; + printMacroExpansions := lPrintMacroExpansions; + nToken := token; + PutBackToken(nToken, false); + token := lToken; + if nToken.kind <> colonch then + DoDeclaration(false) + else + hasStatementNext := true; + end {else} + end; {else if} + + if hasStatementNext then begin if statementList^.doingDeclaration then begin statementList^.doingDeclaration := false; if firstCompoundStatement then begin