forked from qt-creator/qt-creator
CPlusPlus: Fix crash on weird-looking construct
This was misparsed as a function with an initializer (e.g. "= default"), and then the empty id caused trouble later on. Fixes: QTCREATORBUG-29386 Change-Id: I85a35db544e11ad85f50e3a15b1a071b36e79cd0 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
5
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
5
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -3020,6 +3020,11 @@ bool Parser::parseInitDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_sp
|
||||
if (!_languageFeatures.cxx11Enabled || LA(2) == T_NUMERIC_LITERAL) {
|
||||
parseInitializer(node->initializer, &node->equal_token);
|
||||
} else {
|
||||
if (LA(2) != T_NUMERIC_LITERAL && LA(2) != T_DEFAULT && LA(2) != T_DELETE) {
|
||||
error(cursor(), "expected 'default', 'delete' or '0', got '%s'", tok(2).spell());
|
||||
return false;
|
||||
}
|
||||
|
||||
node->equal_token = consumeToken();
|
||||
|
||||
IdExpressionAST *id_expr = new (_pool) IdExpressionAST;
|
||||
|
@@ -190,6 +190,7 @@ private slots:
|
||||
void enumDeclaration();
|
||||
void invalidEnumClassDeclaration();
|
||||
void invalidEnumWithDestructorId();
|
||||
void invalidFunctionInitializer();
|
||||
};
|
||||
|
||||
void tst_AST::gcc_attributes_1()
|
||||
@@ -2052,6 +2053,14 @@ void tst_AST::invalidEnumWithDestructorId()
|
||||
QVERIFY(diag.errorCount != 0);
|
||||
}
|
||||
|
||||
void tst_AST::invalidFunctionInitializer()
|
||||
{
|
||||
QSharedPointer<TranslationUnit> unit(parse(
|
||||
"int main() { a t=b; c d(e)=\"\"; }", TranslationUnit::ParseTranlationUnit, false, false, true));
|
||||
|
||||
QVERIFY(diag.errorCount != 0);
|
||||
}
|
||||
|
||||
void tst_AST::initTestCase()
|
||||
{
|
||||
control.setDiagnosticClient(&diag);
|
||||
|
Reference in New Issue
Block a user