Fixed #8197 (iscast: '(b)&1' is not a cast)

This commit is contained in:
Daniel Marjamäki 2017-09-08 22:52:16 +02:00
parent b81b4fcb78
commit b9b47809f9
4 changed files with 11 additions and 3 deletions

View File

@ -644,6 +644,12 @@
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="PRECT" value="RECT">
<pointer/>
<platform type="win32A"/>
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="PSTR" value="char">
<pointer/>
<platform type="win32A"/>

View File

@ -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;

View File

@ -8334,6 +8334,7 @@ private:
// not cast
ASSERT_EQUALS("AB||", testAst("(A)||(B)"));
ASSERT_EQUALS("abc[1&=", testAst("a = (b[c]) & 1;"));
}
void astlambda() {

View File

@ -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());