Fixed #8418 (AST: wrong ast for throw expression)

This commit is contained in:
Daniel Marjamäki 2018-03-10 22:30:21 +01:00
parent 7ba9ab7e4c
commit 380ecc408f
2 changed files with 4 additions and 2 deletions

View File

@ -550,7 +550,7 @@ static void compileTerm(Token *&tok, AST_state& state)
tok = tok->next();
} while (Token::Match(tok, "%name%|%str%"));
} else if (tok->isName()) {
if (Token::Match(tok, "return|case")) {
if (Token::Match(tok, "return|case") || (state.cpp && tok->str() == "throw")) {
if (tok->str() == "case")
state.inCase = true;
compileUnaryOp(tok, state, compileExpression);
@ -1137,7 +1137,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
if (Token::Match(tok, "%type% <") && !Token::Match(tok->linkAt(1), "> [({]"))
return tok->linkAt(1);
if (Token::Match(tok, "return|case") || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?|;") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) {
if (Token::Match(tok, "return|case") || (cpp && tok->str() == "throw") || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?|;") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) {
if (cpp && (Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%") || Token::Match(tok->tokAt(-3), "[;{}] :: new|delete %name%")))
tok = tok->previous();

View File

@ -8363,6 +8363,8 @@ private:
ASSERT_EQUALS("ab.++", testAst("a.b++;"));
ASSERT_EQUALS("ab::++", testAst("a::b++;"));
ASSERT_EQUALS("c5[--*", testAst("*c[5]--;"));
ASSERT_EQUALS("xreturn", testAst("return x;"));
ASSERT_EQUALS("x(throw", testAst(";throw x();"));
ASSERT_EQUALS("a*bc:?return", testAst("return *a ? b : c;"));
// Unary :: operator