Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#20 parse error on variable initialized in for loop

v3.1.3
open
nobody
None
5
2012-06-03
2012-06-03
Steve Chapel
No

The following program (forinit.c):

void f() {
for (int i = 0; i < 5; i++)
;
}

causes splint to give the error:

forinit.c:2:13: Parse Error. (For help on parse errors, see splint -help
parseerrors.)
*** Cannot continue.

This occurs with splint 3.1.2 and the version in CVS.

Here is a patch for cgrammar.y that fixes the parse error:

1748a1749,1753
> | CFOR TLPAREN completeTypeSpecifier optExpr TSEMI optExpr TSEMI
> { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
> TRPAREN
> { $$ = exprNode_forPred ($4, $6, $9);
> context_enterForClause ($6); }

But this causes the variable i to be considered undeclared in the above code.

Discussion