CPlusPlus: Add missing error check to parseExpressionStatement()

Fixes: QTCREATORBUG-32043
Change-Id: Ic4f1716339d1277d0a2d5a237fd6ae0389ed2485
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2024-11-25 13:25:47 +01:00
parent 95f384d62c
commit d1a662dbea
2 changed files with 15 additions and 11 deletions

View File

@@ -487,15 +487,17 @@ int Parser::find(int token, int stopAt)
return 0;
}
void Parser::match(int kind, int *token)
bool Parser::match(int kind, int *token)
{
if (LA() == kind)
if (LA() == kind) {
*token = consumeToken();
else {
return true;
}
*token = 0;
error(_tokenIndex, "expected token `%s' got `%s'",
Token::name(kind), tok().spell());
}
return false;
}
bool Parser::parseClassOrNamespaceName(NameAST *&node)
@@ -3503,7 +3505,8 @@ bool Parser::parseExpressionStatement(StatementAST *&node)
DEBUG_THIS_RULE();
if (LA() == T_SEMICOLON) {
ExpressionStatementAST *ast = new (_pool) ExpressionStatementAST;
match(T_SEMICOLON, &ast->semicolon_token);
if (!match(T_SEMICOLON, &ast->semicolon_token))
return false;
node = ast;
return true;
}
@@ -3524,10 +3527,11 @@ bool Parser::parseExpressionStatement(StatementAST *&node)
ExpressionStatementAST *ast = new (previousPool) ExpressionStatementAST;
if (expression)
ast->expression = expression->clone(previousPool);
match(T_SEMICOLON, &ast->semicolon_token);
if (match(T_SEMICOLON, &ast->semicolon_token)) {
node = ast;
parsed = true;
}
}
_inExpressionStatement = wasInExpressionStatement;

View File

@@ -273,7 +273,7 @@ public:
const Identifier *className(ClassSpecifierAST *ast) const;
const Identifier *identifier(NameAST *name) const;
void match(int kind, int *token);
bool match(int kind, int *token);
bool maybeAmbiguousStatement(DeclarationStatementAST *ast, StatementAST *&node);
bool maybeForwardOrClassDeclaration(SpecifierListAST *decl_specifier_seq) const;