diff --git a/shared/cplusplus/Parser.cpp b/shared/cplusplus/Parser.cpp index 13fbaa0160b6185e3a9609085d10c13f708fa97c..13ca6b2074cd09ce5c41e78d1511d4e6eb28ef18 100644 --- a/shared/cplusplus/Parser.cpp +++ b/shared/cplusplus/Parser.cpp @@ -1760,7 +1760,7 @@ bool Parser::parseReturnStatement(StatementAST *&node) return false; } -bool Parser::maybeFunctionCall(SimpleDeclarationAST *simpleDecl) +bool Parser::maybeFunctionCall(SimpleDeclarationAST *simpleDecl) const { if (! simpleDecl) return false; @@ -1798,6 +1798,17 @@ bool Parser::maybeFunctionCall(SimpleDeclarationAST *simpleDecl) return true; } +bool Parser::maybeSimpleExpression(SimpleDeclarationAST *simpleDecl) const +{ + if (! simpleDecl->declarators) { + SpecifierAST *spec = simpleDecl->decl_specifier_seq; + if (spec && ! spec->next && spec->asNamedTypeSpecifier()) { + return true; + } + } + return false; +} + bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node) { if (LA() == T_SEMICOLON) @@ -1810,7 +1821,9 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node) SimpleDeclarationAST *simpleDecl = 0; if (stmt->declaration) simpleDecl = stmt->declaration->asSimpleDeclaration(); - if (simpleDecl && simpleDecl->decl_specifier_seq && ! maybeFunctionCall(simpleDecl)) { + + if (simpleDecl && simpleDecl->decl_specifier_seq && + ! maybeFunctionCall(simpleDecl) && ! maybeSimpleExpression(simpleDecl)) { unsigned end_of_declaration_statement = cursor(); rewind(start); StatementAST *expression = 0; @@ -1827,6 +1840,7 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node) return true; } } + blockErrors(blocked); rewind(start); return parseExpressionStatement(node); diff --git a/shared/cplusplus/Parser.h b/shared/cplusplus/Parser.h index f35b20416603c910bfc839f8b9fdb52530611e1e..fbaf423b6f5c682b13052b5fe20ca733035b8dc3 100644 --- a/shared/cplusplus/Parser.h +++ b/shared/cplusplus/Parser.h @@ -220,7 +220,8 @@ public: void match(int kind, unsigned *token); - bool maybeFunctionCall(SimpleDeclarationAST *simpleDecl); + bool maybeFunctionCall(SimpleDeclarationAST *simpleDecl) const; + bool maybeSimpleExpression(SimpleDeclarationAST *simpleDecl) const; private: bool switchTemplateArguments(bool templateArguments); diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp index 93ad454e563487cd19e4726cf54c1d31f43040c2..5638106ed832573609716d1356b3de82b1d82b62 100644 --- a/tests/auto/cplusplus/ast/tst_ast.cpp +++ b/tests/auto/cplusplus/ast/tst_ast.cpp @@ -31,6 +31,7 @@ public: private slots: void if_statement(); void if_else_statement(); + void cpp_initializer(); }; void tst_AST::if_statement() @@ -49,6 +50,16 @@ void tst_AST::if_statement() QVERIFY(stmt->statement != 0); QCOMPARE(stmt->else_token, 0U); QVERIFY(stmt->else_statement == 0); + + // check the `then' statement + ExpressionStatementAST *then_stmt = stmt->statement->asExpressionStatement(); + QVERIFY(then_stmt != 0); + QVERIFY(then_stmt->expression != 0); + QCOMPARE(then_stmt->semicolon_token, 6U); + + SimpleNameAST *id_expr = then_stmt->expression->asSimpleName(); + QVERIFY(id_expr != 0); + QCOMPARE(id_expr->identifier_token, 5U); } void tst_AST::if_else_statement() @@ -69,5 +80,13 @@ void tst_AST::if_else_statement() QVERIFY(stmt->else_statement != 0); } +void tst_AST::cpp_initializer() +{ + QSharedPointer<TranslationUnit> unit(parseStatement("QFileInfo fileInfo(foo);")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); +} + + QTEST_APPLESS_MAIN(tst_AST) #include "tst_ast.moc" diff --git a/tests/auto/cplusplus/shared/shared.pri b/tests/auto/cplusplus/shared/shared.pri index bcb756ea34bdec219d05f0a1e9e8397bbab95959..175dba7cfeae42b2bd4232d8c504e5adc26df386 100644 --- a/tests/auto/cplusplus/shared/shared.pri +++ b/tests/auto/cplusplus/shared/shared.pri @@ -1,4 +1,5 @@ DEFINES += HAVE_QT CPLUSPLUS_WITH_NAMESPACE INCLUDEPATH += $$PWD/../../../../shared/cplusplus +DEPENDPATH += $$INCLUDEPATH . LIBS += -L$$PWD -lCPlusPlusTestSupport