diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp index 904f1a31892d0034ae2360861860ccb9db8da15b..61efa2baa82c6880e2cf48b3c2d58a34be62dd68 100644 --- a/src/shared/cplusplus/Parser.cpp +++ b/src/shared/cplusplus/Parser.cpp @@ -182,7 +182,10 @@ inline bool isRightAssociative(int tokenKind) #endif #define PARSE_EXPRESSION_WITH_OPERATOR_PRECEDENCE(node, minPrecedence) { \ - if (!parseCastExpression(node)) \ + if (LA() == T_THROW) { \ + if (!parseThrowExpression(node)) \ + return false; \ + } else if (!parseCastExpression(node)) \ return false; \ \ parseExpressionWithOperatorPrecedence(node, minPrecedence); \ @@ -2322,14 +2325,27 @@ bool Parser::parseStringLiteral(ExpressionAST *&node) bool Parser::parseExpressionStatement(StatementAST *&node) { DEBUG_THIS_RULE(); - ExpressionAST *expression = 0; - if (LA() == T_SEMICOLON || parseExpression(expression)) { + if (LA() == T_SEMICOLON) { ExpressionStatementAST *ast = new (_pool) ExpressionStatementAST; - ast->expression = expression; match(T_SEMICOLON, &ast->semicolon_token); node = ast; return true; } + + ExpressionAST *expression = 0; + MemoryPool *oldPool = _pool; + MemoryPool tmp; + _pool = &tmp; + if (parseExpression(expression)) { + ExpressionStatementAST *ast = new (oldPool) ExpressionStatementAST; + ast->expression = expression->clone(oldPool); + match(T_SEMICOLON, &ast->semicolon_token); + node = ast; + _pool = oldPool; + return true; + } + _pool = oldPool; + return false; } diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp index c9c8b73f46370b0c31db5d9301c5085112c9a89e..b23bd76eea795b0ccd72843a68df92a718a49296 100644 --- a/tests/auto/cplusplus/ast/tst_ast.cpp +++ b/tests/auto/cplusplus/ast/tst_ast.cpp @@ -51,6 +51,7 @@ private slots: void condition_1(); void init_1(); void conditional_1(); + void throw_1(); // statements void if_statement_1(); @@ -341,6 +342,14 @@ void tst_AST::conditional_1() QCOMPARE(unit->spell(one->literal_token), "1"); } +void tst_AST::throw_1() +{ + QSharedPointer<TranslationUnit> unit(parseStatement("throw 1;")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); + QVERIFY(ast->asExpressionStatement()); +} + void tst_AST::function_call_1() { QSharedPointer<TranslationUnit> unit(parseStatement("retranslateUi(blah);"));