From b9b47809f93adcfd8647d065a1020a6f52d9ce45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 8 Sep 2017 22:52:16 +0200 Subject: [PATCH] Fixed #8197 (iscast: '(b)&1' is not a cast) --- cfg/windows.cfg | 6 ++++++ lib/tokenlist.cpp | 5 +++-- test/testtokenize.cpp | 1 + test/testuninitvar.cpp | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cfg/windows.cfg b/cfg/windows.cfg index 3fe2f36ea..f4bb67aaf 100644 --- a/cfg/windows.cfg +++ b/cfg/windows.cfg @@ -644,6 +644,12 @@ + + + + + + diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 76f95bf47..2fa66ee62 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -368,11 +368,12 @@ static bool iscast(const Token *tok) while (tok2->link() && Token::Match(tok2, "(|[|<")) tok2 = tok2->link()->next(); - if (tok2->str() == ")") - return type || tok2->strAt(-1) == "*" || Token::Match(tok2, ") &|~") || + if (tok2->str() == ")") { + return type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") || (Token::Match(tok2, ") %any%") && !tok2->next()->isOp() && !Token::Match(tok2->next(), "[[]);,?:.]")); + } if (!Token::Match(tok2, "%name%|*|&|::")) return false; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 78e1810ca..86e710a0d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8334,6 +8334,7 @@ private: // not cast ASSERT_EQUALS("AB||", testAst("(A)||(B)")); + ASSERT_EQUALS("abc[1&=", testAst("a = (b[c]) & 1;")); } void astlambda() { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 963a29ad6..3a01d9724 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2553,7 +2553,7 @@ private: checkUninitVar("void f() {\n" // #4439 - cast address of uninitialized variable " int a;\n" - " x((A)(B)&a);\n" + " x((LPARAM)(RECT*)&a);\n" "}"); ASSERT_EQUALS("", errout.str());