using boolean result in bitwise operation. fix false positive for '.. != (char *) &x'

This commit is contained in:
Daniel Marjamäki 2011-08-19 18:55:20 +02:00
parent 2dd1e290eb
commit a735790e77
2 changed files with 13 additions and 1 deletions

View File

@ -169,9 +169,16 @@ void CheckOther::clarifyCondition()
// using boolean result in bitwise operation ! x [&|^]
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (Token::Match(tok, "!|<|<=|==|!=|>|>= !!&"))
if (Token::Match(tok, "!|<|<=|==|!=|>|>="))
{
const Token *tok2 = tok->next();
// Todo: There are false positives if '(' if encountered. It
// is assumed there is something like '(char *)&..' and therefore
// it bails out.
if (Token::Match(tok2, "(|&"))
continue;
while (tok2 && (tok2->isName() || tok2->isNumber() || Token::Match(tok2,".|(|[")))
{
if (Token::Match(tok2, "(|["))

View File

@ -2682,6 +2682,11 @@ private:
check("void f() { A<x &> a; }");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" if (result != (char *)&inline_result) { }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void incorrectStringCompare()