diff options
author | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-10-08 11:04:33 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-10-15 10:08:19 +0200 |
commit | 390b4f0e0b544c713fbac4369131fa9b80d60b1a (patch) | |
tree | e3070240995c188b6d8f646ece9e1e2f200bd342 /tests | |
parent | c2eb91e053332d010adc8b9e7918d9de28ef4c90 (diff) | |
download | qt-creator-390b4f0e0b544c713fbac4369131fa9b80d60b1a.tar.gz |
C++: Fix parsing of "Foo *foo = new Foo()"
It should be parsed as an DeclarationStatement, but instead it was
parsed as an ExpressionStatement.
Regression introduced with
commit d3c5fff66de034e46e825b63943909d36067405f.
C++: Fix expensive parsing of expressions
The introduced ASTCache did not save the correct return value of a
parse* function. Because of that, the first return in
Parser::parseExpressionList returned false on the second invocation
(cache hit), instead of true, which resulted in an ExpressionStatement.
Task-number: QTCREATORBUG-13122
Change-Id: I8dbd8852b0909edddcd3195b484f4cea92328cc5
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/cplusplus/ast/tst_ast.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp index 3d3259dd88..1691919012 100644 --- a/tests/auto/cplusplus/ast/tst_ast.cpp +++ b/tests/auto/cplusplus/ast/tst_ast.cpp @@ -50,10 +50,12 @@ public: TranslationUnit *parse(const QByteArray &source, TranslationUnit::ParseMode mode, bool blockErrors = false, - bool qtMocRun = false) + bool qtMocRun = false, + bool cxx11Enabled = false) { const StringLiteral *fileId = control.stringLiteral("<stdin>"); LanguageFeatures features; + features.cxx11Enabled = cxx11Enabled; features.objCEnabled = true; features.qtEnabled = qtMocRun; features.qtKeywordsEnabled = qtMocRun; @@ -79,8 +81,8 @@ public: TranslationUnit *parseExpression(const QByteArray &source) { return parse(source, TranslationUnit::ParseExpression); } - TranslationUnit *parseStatement(const QByteArray &source) - { return parse(source, TranslationUnit::ParseStatement); } + TranslationUnit *parseStatement(const QByteArray &source, bool cxx11Enabled = false) + { return parse(source, TranslationUnit::ParseStatement, false, false, cxx11Enabled); } class Diagnostic: public DiagnosticClient { public: @@ -191,6 +193,8 @@ private slots: // Qt "keywords" void q_enum_1(); + void declarationWithNewStatement(); + void declarationWithNewStatement_data(); void incomplete_ast(); void unnamed_class(); void unnamed_class_data(); @@ -1748,6 +1752,26 @@ void tst_AST::q_enum_1() QCOMPARE(unit->spell(e->identifier_token), "e"); } +void tst_AST::declarationWithNewStatement() +{ + QFETCH(QByteArray, source); + + QSharedPointer<TranslationUnit> unit(parseStatement(source, true)); + AST *ast = unit->ast(); + QVERIFY(ast); + QVERIFY(ast->asDeclarationStatement()); +} + +void tst_AST::declarationWithNewStatement_data() +{ + QTest::addColumn<QByteArray>("source"); + + typedef QByteArray _; + QTest::newRow("withoutParentheses") << _("Foo *foo = new Foo;"); + QTest::newRow("withParentheses") << _("Foo *foo = new Foo();"); + QTest::newRow("withParenthesesAndOneArgument") << _("Foo *foo = new Foo(1);"); +} + void tst_AST::incomplete_ast() { QSharedPointer<TranslationUnit> unit(parseStatement("class A { virtual void a() =\n")); |