From 380ecc408fc81c0743af02b1174b45441ebd639e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 10 Mar 2018 22:30:21 +0100 Subject: [PATCH] Fixed #8418 (AST: wrong ast for throw expression) --- lib/tokenlist.cpp | 4 ++-- test/testtokenize.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index c77a59860..2eaf1e1b2 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7a2a87540..1246d70a3 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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