From 5d086d60ad34d54939b83eef9a4d73685e2d47d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 14 Nov 2018 21:05:03 +0100 Subject: [PATCH] Fixed #8844 (snd: Wrong varid and ast) --- lib/tokenlist.cpp | 18 ++++++++---------- test/testtokenize.cpp | 2 ++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 5194c902e..57ced79c2 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -414,10 +414,15 @@ static bool iscast(const Token *tok) bool type = false; for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { + if (tok2->varId() != 0) + return false; + while (tok2->link() && Token::Match(tok2, "(|[|<")) tok2 = tok2->link()->next(); if (tok2->str() == ")") { + if (Token::simpleMatch(tok2, ") (") && Token::simpleMatch(tok2->linkAt(1), ") .")) + return true; return type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") || (Token::Match(tok2, ") %any%") && !tok2->next()->isOp() && @@ -757,17 +762,10 @@ static void compilePrecedence3(Token *&tok, AST_state& state) } compileUnaryOp(tok, state, compilePrecedence3); } else if (tok->str() == "(" && iscast(tok)) { - Token* tok2 = tok; + Token* castTok = tok; tok = tok->link()->next(); - if (tok && tok->str() == "(" && !iscast(tok)) { - Token *tok3 = tok->next(); - compileExpression(tok3, state); - if (tok->link() == tok3) - tok = tok3->next(); - } else { - compilePrecedence3(tok, state); - } - compileUnaryOp(tok2, state, nullptr); + compilePrecedence3(tok, state); + compileUnaryOp(castTok, state, nullptr); } else if (state.cpp && Token::Match(tok, "new %name%|::|(")) { Token* newtok = tok; tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d0d591e47..46c666ddf 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8536,6 +8536,8 @@ private: ASSERT_EQUALS("xatoistr({(=", testAst("x = (struct X){atoi(str)};")); ASSERT_EQUALS("xa.0=b.0=,c.0=,{(=", testAst("x = (struct abc) { .a=0, .b=0, .c=0 };")); + ASSERT_EQUALS("yz.(return", testAst("return (x)(y).z;")); + // not cast ASSERT_EQUALS("AB||", testAst("(A)||(B)")); ASSERT_EQUALS("abc[1&=", testAst("a = (b[c]) & 1;"));